Changing variable from appdesigner in matlab script

Hello,
How can I send a value for a variable from appdesigner to the workspace which is then used in a matlab script?

 채택된 답변

Eric Delgado
Eric Delgado 2022년 10월 5일
You can use assignin to send the variable to Matlab base workspace.
% Suppose that you have a variable named "app.myVariable"
assignin('base', 'myVariable', app.myVariable)
openvar('myVariable')

댓글 수: 6

thanks Eric!,
the variable appears in the workspace, but if I want to run a script afterwards the variable is not recognized.
What is your purpose?! If the variables are in the base Matlab workspace, yes, you can call it from a script. But if you're trying to change your app's data and bring it back into your app, you should use a function instead of a script.
app.myVariable = MyFunction(app.myVariable);
example:
function StartButtonPushed(app, event)
assignin('base','MyResolution',app.myVariable)
testscript;
end
In the testscript the value for myResolution should be used. Btw it s also not working if I use instead of the base workspace the function workspace('caller').
Hey, don't use assignin to pass your app properties to a script. Just transform your script into a function and call it, passing your app properties as input arguments. See below and code attached.
Thank you so much Eric! Now it works
Great to hear! Now that you are super happy with my support, you accept my answer, ok? :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Desktop에 대해 자세히 알아보기

태그

질문:

2022년 10월 5일

댓글:

2022년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by