Trouble passing guidata to new .m files
Afficher commentaires plus anciens
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.
Réponses (1)
Matt Fig
le 10 Juin 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 commentaires
Marvin
le 10 Juin 2011
Matt Fig
le 10 Juin 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
le 13 Juin 2011
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!