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 日

1 投票

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 件のコメント

Furkan Karaman
Furkan Karaman 2022 年 10 月 8 日
thanks Eric!,
the variable appears in the workspace, but if I want to run a script afterwards the variable is not recognized.
Eric Delgado
Eric Delgado 2022 年 10 月 10 日
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);
Furkan Karaman
Furkan Karaman 2022 年 10 月 12 日
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').
Eric Delgado
Eric Delgado 2022 年 10 月 14 日
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.
Furkan Karaman
Furkan Karaman 2022 年 10 月 19 日
Thank you so much Eric! Now it works
Eric Delgado
Eric Delgado 2022 年 10 月 21 日
Great to hear! Now that you are super happy with my support, you accept my answer, ok? :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by