フィルターのクリア

Transferring variables between functions using the GUI (guide)?

2 ビュー (過去 30 日間)
Cliff
Cliff 2012 年 8 月 8 日
I have a script file (MainProgram.m) that is the main part of my program. Upon execution, this script file then calls many functions within itself to perform the necessary tasks and leaves me with some plots, etc. and a set of variables in the Workspace. Everything is working as it should.
Now, I'm trying to incorporate a GUI using guide, but am having some trouble "seeing" any of the variables in the Workspace. Essentially, I want someone to execute MainProgram.m when they click a certain button in the GUI and then I want ALL the variables that are left after MainProgram.m runs to be avaiable for subsequent button clicks in the GUI (which essentially, will look-up, test, etc. the data that comes from MainProgram.m).
Can anyone offer any advice? Thanks in advance.
~Cliff

採用された回答

Sumit Tandon
Sumit Tandon 2012 年 8 月 8 日
The issue here is that a GUI is essentially a function in MATLAB with its own "workspace" or "scope" where variables reside.
A script, on the other hand, always works in the "base workspace" which is visible by default in the Workspace Browser.
This page in documentation explains these concepts in some more detail.
Ideally you would want to allocate the variables in the GUI itself (say in the opening function) and then use data structures like the HANDLES structure. GUIDATA or APPDATA to share the variables among the different callbacks.
You could also use EVALIN or ASSIGNIN to talk directly with base workspace.
This link in documentation has good information about data management in GUIs.
  1 件のコメント
Cliff
Cliff 2012 年 8 月 8 日
Great; thanks Sumit! I am fairly new to GUI, so your documentation references are a big help. Looking at other posts using assignin, it looks like I can pair that with who() to get a list of all the variables after MainProgram.m runs. Then, I need only run assignin recursively to import all the variables into the GUI's Workspace. As you noted, that's most likely not the ideal method, but at this time, I'm not sure how many more variables I will have to introduce through MainProgram.m.
Anywho, thanks again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by