Trouble passing guidata to new .m files

I have generated a programmatic GUI that has popup menu. I am trying to figure out how to modify the string in that popup menu from a function in a different .m file. I have tried using guidata and guihandles but am not sure what I am doing wrong.
Thanks.

Answers (1)

In order to use GUIDATA, you need the handle of the GUI. So to get the guidata of a figure with handle H,
GD = guidata(H);
If the GUI was created by GUIDE, the handle will be invisible to gcf, but you can get around this. Set a tag for the GUI figure, say 'myguitag' then use:
GD = guidata(findall(0,'tag','myguitag'))
Even if the GUI was not created by GUIDE, this will work as longs as you tag the figure with the appropriate tag.
Also of note: I assume you know, but I just want to make sure, the GUI must be open when looking for the handle. If you create data with the GUI then close it to process the data with another M-file, you will need to save the data before closing the GUI. You could save it as a MAT-file, or save it in the userdata of the root, or whatever...

3 Comments

Where would I find the handle for this popupmenu?
When I call the function do I just have to pass "GD" in order to be able to change the handles?
I was thinking you would call GUIDATA inside the M-file. If not, call it from anywhere then look at the structure. If it is a GUIDE GUI, one of the fieldnames will be something like popupmenu1.
GD = guidata(findall(0,'tag','myguitag'));
GD.popupmenu1 % Handle to the popupmenu - EXAMPLE ONLY - Check first!
Then you can either pass GD.popupmenu1 to the function or whatever.
I'm not using GUIDE to make this GUI but I was able to manipulate my popupmenu by simply passing the popupmenu from the function call. For example:
popupmenu1 = uicontrol('Style','popupmenu',...
%used to access and manipulate popupmenu info
gui_manipulate_function(popupmenu1);
Where gui_manipulate_function is its own .m file.
Is this a less efficient way to pass information?

Sign in to comment.

Categories

Products

Asked:

on 10 Jun 2011

Community Treasure Hunt

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

Start Hunting!