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?

 Akzeptierte Antwort

Eric Delgado
Eric Delgado am 5 Okt. 2022
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 Kommentare

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? :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by