how to pass data to sub-gui using guidata

1 Ansicht (letzte 30 Tage)
A
A am 14 Dez. 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.

Antworten (1)

Sean de Wolski
Sean de Wolski am 14 Dez. 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 Kommentare
A
A am 14 Dez. 2012
Bearbeitet: A am 14 Dez. 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 am 17 Dez. 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:

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by