Writing function that includes EV3

2 views (last 30 days)
Nathaniel Syverson
Nathaniel Syverson on 26 Nov 2018
Edited: Kenny Shu on 28 Nov 2018
I am working with the EV3 package and am trying to write a function that includes various sensor inputs and outputs a numerical value depending on the sensor readings. When I try to run it it give the error "undefined function or variable 'myev3' "even though I have already defined it as a lego ev3. I have tried redefining the 'myev3' as a lego ev3 but then get the error that there is already an ev3 assigned to the usb. Is it possible to write functions like this or do I need to write everything in the script?

Answers (1)

Kenny Shu
Kenny Shu on 28 Nov 2018
Edited: Kenny Shu on 28 Nov 2018
I sounds like "myev3"' is being defined outside of the scope of the function. If "myev3" is defined in the MATLAB base workspace, it will not be accessible from the function workspace.
You can pass "myev3" into the function instead:
myev3 = legoev3('usb')
myfunc(myev3)
function myfunc (mylego)
beep(mylego)
end
You can refer to the following links for more information about working with function workspaces.
https://www.mathworks.com/help/matlab/matlab_prog/share-data-between-workspaces.html

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!