Writing function that includes EV3

조회 수: 5 (최근 30일)
Nathaniel Syverson
Nathaniel Syverson 2018년 11월 26일
편집: Kenny Shu 2018년 11월 28일
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?

답변 (1개)

Kenny Shu
Kenny Shu 2018년 11월 28일
편집: Kenny Shu 2018년 11월 28일
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

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by