Writing function that includes EV3

4 Ansichten (letzte 30 Tage)
Nathaniel Syverson
Nathaniel Syverson am 26 Nov. 2018
Bearbeitet: Kenny Shu am 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?

Antworten (1)

Kenny Shu
Kenny Shu am 28 Nov. 2018
Bearbeitet: Kenny Shu am 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

Kategorien

Mehr zu LEGO MINDSTORMS EV3 Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by