Variable usage in Callbacks
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!