how to pass data to sub-gui using guidata

1 visualizzazione (ultimi 30 giorni)
A
A il 14 Dic 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.

Risposte (1)

Sean de Wolski
Sean de Wolski il 14 Dic 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 Commenti
A
A il 14 Dic 2012
Modificato: A il 14 Dic 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 il 17 Dic 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:

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by