Trouble passing guidata to new .m files
Mostra commenti meno recenti
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.
Risposte (1)
Matt Fig
il 10 Giu 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 Commenti
Marvin
il 10 Giu 2011
Matt Fig
il 10 Giu 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
il 13 Giu 2011
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!