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.
回答 (1 件)
Matt Fig
2011 年 6 月 10 日
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 件のコメント
Marvin
2011 年 6 月 10 日
Matt Fig
2011 年 6 月 10 日
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
2011 年 6 月 13 日
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!