GUI and two .figs

1 visualización (últimos 30 días)
john
john el 1 de Jul. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Jul. de 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 comentarios
Walter Roberson
Walter Roberson el 5 de Jul. de 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 el 8 de Jul. de 2013
ok

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by