Pass variables/structure to .mlapp (GUI/App designer)

13 ビュー (過去 30 日間)
Ashishkumar Gupta
Ashishkumar Gupta 2023 年 1 月 8 日
回答済み: chrisw23 2023 年 2 月 9 日
Hello,
I want to run my matlab script (.m file) amd want to pass data to GUI/.mlapp from my .m file(matlab script) workspace. The data can be a variable/structure.
Also, I want GUI to also pass some data back to .m file.
Thanks !!!

採用された回答

Cameron
Cameron 2023 年 1 月 8 日
evalin and assignin are the functions that should help. For example, if you are running App Designer and you have a variable called MyVar you could use this to take the variable and send it to the workspace:
assignin('base','MyVar',MyVar)
%assignin('base',Workspace variable name,The variable)
  2 件のコメント
Ashishkumar Gupta
Ashishkumar Gupta 2023 年 1 月 8 日
編集済み: Ashishkumar Gupta 2023 年 1 月 8 日
Unfortunately, it is not recommended by matlab to use evalin. Is there any alternative ways? @Cameron Thanks!!
Cameron
Cameron 2023 年 1 月 9 日
As @Image Analyst said below, you can use the save and load functions. Those are generally more accepted.

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

その他の回答 (3 件)

Image Analyst
Image Analyst 2023 年 1 月 9 日
If you have a script that creates some data, you can use save in your script to save the variables, and use load to read them in in your .mlapp code.
See the FAQ for other ways:

Walter Roberson
Walter Roberson 2023 年 1 月 9 日
App designer creates code that defines an object class the derives from handle.
At least in theory, you could modify the constructor to accept additional parameters. Or probably better would be adding methods that accepted the handle object and the additional data, and performed an action and returned appropriate values.
Remember though that if you want to get out the results after user interaction then you will need to arrange for the code to wait for interactions to finish before you can return. See uiwait and waitfor

chrisw23
chrisw23 2023 年 2 月 9 日
Calling your mlapp application from your script returns the app handle with full access to all public objects
myAppHandle = myApp()
Observed properties are an option to establish an event structure for bidirectional communication.

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by