How to access GUI workspace?

17 views (last 30 days)
Kyle
Kyle on 13 Jul 2011
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.

Answers (3)

Yoav Livneh
Yoav Livneh on 13 Jul 2011
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 on 13 Jul 2011

Walter Roberson
Walter Roberson on 13 Jul 2011
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.

Community Treasure Hunt

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

Start Hunting!