GUI and two .figs
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have two .figs. If I press button in fig 1, than is executed callback
function button_Callback(hObject, eventdata, handles)
h=findobj(0,'Type','figure','Tag','figure1');
UserData=get(h,'UserData');
UserData.a
open mm.fig
;
set(h,'UserData',UserData);
guidata(hObject, handles);
and figure mm.fig is open. But if I press again the same button like above, than I get error in UserData.a ??? Attempt to reference field of non-structure array.
Why I lose info about UserData.a???
Thanks
0 个评论
采纳的回答
Walter Roberson
2013-7-1
If both figures have the tag 'figure1' then the findobj() is going to return a vector of handles and the get() of Userdata would return a cell array.
3 个评论
Walter Roberson
2013-7-5
Set a breakpoint at the assignment to Userdata, and run the program. When it stops, check size(h) .
Is "h" empty? If so then there are somehow no figures that have that Tag associated; that could happen if a "clear all" was executed.
The first time through, "h" would be expected to be a single element. As your routine works the first time through, once you have verified that, you could use "dbcont" to continue, and then press the button again. The second time through, you need to pay attention to the size of "h"
If "h" becomes a vector of more than one element, then get(h,'UserData') will return a cell array, with one member for each element in "h". "h" could end up with more than one element if there are now two figures that have the tag 'figure1'. That could happen if the GUIDE for both GUI used 'figure1' as the name of the figure. "Don't do that". Use the property editor in GUIDE to change the names associated with the two figures.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!