GUI and two .figs
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 1 Juil 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 commentaires
Walter Roberson
le 5 Juil 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!