GUI and two .figs

조회 수: 6 (최근 30일)
john
john 2013년 7월 1일
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

채택된 답변

Walter Roberson
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
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.
john
john 2013년 7월 8일
ok

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by