Transferring variables between functions using the GUI (guide)?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Install Products에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!