Variable usage in Callbacks

조회 수: 2 (최근 30일)
Subhiksha
Subhiksha 2013년 9월 26일
편집: Jan 2013년 9월 26일
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
Jan
Jan 2013년 9월 26일
Please format your code properly when you want to encourage others to read it.

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

답변 (1개)

Jan
Jan 2013년 9월 26일
편집: Jan 2013년 9월 26일
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by