how to pass data to sub-gui using guidata

1 次查看(过去 30 天)
A
A 2012-12-14
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.

回答(1 个)

Sean de Wolski
Sean de Wolski 2012-12-14
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 个评论
A
A 2012-12-14
编辑:A 2012-12-14
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 2012-12-17
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:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by