How to retrieve data from one gui to another?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nur Fauzira Saidin
am 6 Mai 2015
Kommentiert: Geoff Hayes
am 7 Mai 2015
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149886/image.png)
GUI_2 (pic 2)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149887/image.png)
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 7 Mai 2015
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 Kommentare
Geoff Hayes
am 7 Mai 2015
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!