Trouble passing guidata to new .m files

1 view (last 30 days)
Marvin
Marvin on 10 Jun 2011
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)

Matt Fig
Matt Fig on 10 Jun 2011
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
Matt Fig
Matt Fig on 10 Jun 2011
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.
Marvin
Marvin on 13 Jun 2011
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

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!