GUI and two .figs

5 views (last 30 days)
john
john on 1 Jul 2013
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

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jul 2013
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 Comments
Walter Roberson
Walter Roberson on 5 Jul 2013
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.
john
john on 8 Jul 2013
ok

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!