how to pass data to sub-gui using guidata

1 vue (au cours des 30 derniers jours)
A
A le 14 Déc 2012
I have a pushbutton(pushbutton8) in the main gui that will open another gui(also created using guide). All the data is stored in handles structure using guidata. How do I pass all of that to the second gui? I tried the lines below but it did not work.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
subgui(hObject,eventdata,handles)
end
I know there is a way to do this using getappdata; but I rather use guidata for consistency.

Réponses (1)

Sean de Wolski
Sean de Wolski le 14 Déc 2012
Store the GUIDATA of the first GUI into the GUIDATA of the second, or just use setappdata/getappdata;
f = the_second_gui; %f = second gui figure handle
setappdata(f,'first_gui_info',handles);
Then in the second figure:
h = getappdata(f,'first_gui_info');
  2 commentaires
A
A le 14 Déc 2012
Modifié(e) : A le 14 Déc 2012
I put
h = getappdata(f,'first_gui_info');
in the OpeningFcn or OutputFcn of second gui; it throws error "unknown f". I replaced that with:
h = getappdata(gcf,'first_gui_info');
h turned out to be empty (nothing got passed). Note that second gui has a separate m file.
Sean de Wolski
Sean de Wolski le 17 Déc 2012
Never put anything in the OpeningFcn. As the name suggests, this is called before the GUI exists and thus nothing exists. So put it in the OutputFcn which is called immediately after the GUI becomes visible.
Also:

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps 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!

Translated by