Borrar filtros
Borrar filtros

How to retrieve data from one gui to another?

2 visualizaciones (últimos 30 días)
Nur Fauzira Saidin
Nur Fauzira Saidin el 6 de Mayo de 2015
Comentada: Geoff Hayes el 7 de Mayo de 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)
GUI_2 (pic 2)

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 7 de Mayo de 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 comentarios
Nur Fauzira Saidin
Nur Fauzira Saidin el 7 de Mayo de 2015
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 el 7 de Mayo de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building 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