필터 지우기
필터 지우기

How to retrieve data from one gui to another?

조회 수: 2 (최근 30일)
Nur Fauzira Saidin
Nur Fauzira Saidin 2015년 5월 6일
댓글: Geoff Hayes 2015년 5월 7일
I have two GUIs. The first one I want to plot a sine signal at axes 3 (as in pic 1). My problem is, how can I retrieve back the graph into the axes 1 of the second GUI (as in pic 2) after I clicked the 'load data' pushbutton? I really need help here.
GUI_1 (pic 1)
GUI_2 (pic 2)

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 5월 7일
Nur - see http://www.mathworks.com/matlabcentral/answers/146215-pass-data-between-gui-s as one example on how to pass data between two GUIs.
  댓글 수: 2
Nur Fauzira Saidin
Nur Fauzira Saidin 2015년 5월 7일
I found many example actually but I still couldn't understand it. Can you help? I named my first GUI as 'sine_signal' (tag: gui_sine) and the other GUI as 'filtering' (tag: gui_filtering).
Geoff Hayes
Geoff Hayes 2015년 5월 7일
Nur - there are probably several different ways to do this, so here is one. Let's assume that you have two GUIs named gui_sine and gui_filtering and that they are distinct GUIs (i.e. you are not running two instances of the same one). In the Property Inspector for Gui1, set the HandleVisibility property to on , and the Tag property to gui_sine. This will allow us to search for the GUI given its (unique) tag. Do the same for the other GUI (except name the tag gui_filtering). Save both.
Now suppose that in gui_filtering you want access to some of the data in the first GUI. What you require, is the handle to the latter. In a (say) push button callback of gui_filtering, you can add the following code
function pushbutton1_Callback(hObject, eventdata, handles)
% get the handle of gui_sine
h = findobj('Tag','gui_sine');
% if exists (not empty)
if ~isempty(h)
% get handles and other user-defined data associated to gui_sine
g1data = guidata(h);
% maybe you want to set the text in gui_filtering with that from gui_sine
set(handles.text1,'String',get(g1data.edit1,'String'));
end
The above example tests a way in which we can get data from the other GUI - use either guidata which gives us the handles to all widgets of the first AND any user-defined data that had been saved in that GUI to the handles object as (for example)
function pushbutton3_Callback(hObject, eventdata, handles)
% in some gui_sine callback, we create the following xData field in the handles
% structure
handles.xData = -2*pi:0.0001:2*pi;
% now we save the data
guidata(hObject,handles);
We then access this data as shown previously.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by