Borrar filtros
Borrar filtros

Variable usage in Callbacks

1 visualización (últimos 30 días)
Subhiksha
Subhiksha el 26 de Sept. de 2013
Editada: Jan el 26 de Sept. de 2013
Hello, I have two callback functions named as file_Callback and loaddataset_Callback
function file_Callback(hObject, eventdata, handles) % hObject handle to file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) guidata(hObject,handles) ; %end
% --------------------------------------------------------------------
function dataset=loaddataset_Callback(hObject, eventdata, handles) % hObject handle to loaddataset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %%Load the file from the user interface
%Initialize variables
proceed = 1;
k=1;
disp(a)
while ( proceed == 1 )
%Get the path and name of matfile loaded
[filename,pathname,filterindex]=uigetfile('*.mat');
filepath = [pathname,filename];
%Store the path and name in an array
handles.dataset(k)=cellstr(filepath);
% handles.listbox = '0';
%%confirm if the dataset loaded is right
msg = ['You have loaded ',filename,'. Do you want to load an other dataset of the same subject??'];
load=questdlg(msg, 'Dataset Loaded');
load1 = strcmp (load,'Yes');
%To load another dataset of same subject
if( load1 == 1 )
proceed = 1;
k=k+1;
else
proceed = 0;
end
end
% disp((handles.dataset))
guidata(hObject, handles);
% -------------------------------------------------------------------- %end
I need to declare a variable in file_Callback and use the same variable in loaddataset_Callback.
How to do this??
Thanks in advance
  1 comentario
Jan
Jan el 26 de Sept. de 2013
Please format your code properly when you want to encourage others to read it.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 26 de Sept. de 2013
Editada: Jan el 26 de Sept. de 2013
This topic has been discussed repeatedly here. So please search for "share data GUI" in this forum.
A very useful tool is included in the source code you've posted already: guidata. New variables can be appended to the handles struct, while guidata stores and obtains the current struct to / from the GUI.

Categorías

Más información sobre Workspace Variables and MAT-Files 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