How to access GUI workspace?

17 ビュー (過去 30 日間)
Kyle
Kyle 2011 年 7 月 13 日
Hi,
I'm quite sure matlab has a separate workspace that store all variable for GUI. Does any1 know how to access the workspace?
function button1_Callback(hObject, eventdata, handles)
% hObject handle to Quit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global a;
imshow(a,'parent',handles.im1);
I cleared every variable with the function 'clear'. Then i run the GUI and press a button with above code. The GUI is able to display image 'a' that was called previously.

回答 (3 件)

Yoav Livneh
Yoav Livneh 2011 年 7 月 13 日
CLEAR only clears the current workspace, which is usually 'base'. Your GUI is run from a separate function which has its own workspace, usually the same name as the function.
If you want to access the GUI function variables just put a break point somewhere in the function and then you could examine the variables in that workspace.
You could also use the function ASSIGNIN to send variables to your 'base' workspace and examine them that way.

Image Analyst
Image Analyst 2011 年 7 月 13 日

Walter Roberson
Walter Roberson 2011 年 7 月 13 日
MATLAB does not have "a separate workspace that store all variable for GUI." It has a "base workspace", it has an implicit "global workspace" (for global variables), and it has workspaces for each function (including anonymous functions).
Your issue has to do with it being a global variable you are trying to clear. From the documentation:
clear global name removes the global variable name. If name is global, clear name removes name from the current workspace, but leaves it accessible to any functions declaring it as global. Use clear global name to remove a global variable completely.

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by