Writing function that includes EV3

4 visualizaciones (últimos 30 días)
Nathaniel Syverson
Nathaniel Syverson el 26 de Nov. de 2018
Editada: Kenny Shu el 28 de Nov. de 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?

Respuestas (1)

Kenny Shu
Kenny Shu el 28 de Nov. de 2018
Editada: Kenny Shu el 28 de Nov. de 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

Categorías

Más información sobre LEGO MINDSTORMS EV3 Hardware en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by