how to pass data to sub-gui using guidata

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

Respuestas (1)

Sean de Wolski
Sean de Wolski el 14 de Dic. de 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 comentarios
A
A el 14 de Dic. de 2012
Editada: A el 14 de Dic. de 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 el 17 de Dic. de 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:

Iniciar sesión para comentar.

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