📄 main.m
字号:
% --- Executes on button press in channel_checkbox.function channel_checkbox_Callback(hObject, eventdata, handles)statusbar(handles.figure1,'Program status: Please wait while loading the channels...');hMainGui = getappdata(0, 'hMainGui'); if get(hObject,'Value')==1 setappdata(hMainGui,'VE',get(handles.editchannel1,'String')); setappdata(hMainGui,'HE',get(handles.editchannel2,'String')); setappdata(hMainGui,'RE',get(handles.editchannel3,'String')); chselect; statusbar(handles.figure1); set(hObject,'Value',0);end% --------------------------------------------% Open, Clear, Run, Stop Pushbuttons% --------------------------------------------% --- Executes on button press in openpushbutton.function openpushbutton_Callback(hObject, eventdata, handles)set(handles.channel_checkbox,'Enable','on');prev_handles=handles;keep('prev_handles');sb=statusbar(prev_handles.figure1, 'Program status: Please wait while opening the file...');set(sb.CornerGrip, 'visible','off');set(sb.TextPanel, 'Foreground',[0,0,.5]); % change the statusbar to blue colourselect=1; invalid=1;while(invalid==1) while(select~=0) [fname_data, pathname_data] = uigetfile('*.mat', 'Pick .mat data file'); if isequal(fname_data,0) || isequal(pathname_data,0) statusbar; return else select=0; invalid=0; % to catch if user does not select a file. end end try load([pathname_data fname_data]); % loading files catch statusbar; warn_push1=msgbox('Invalid Data File','Warning','warn','modal'); waitfor(warn_push1); select=1; invalid=1; % to catch if user selected wrong file. endendhMainGui = getappdata(0, 'hMainGui'); str={'fname1','fname2','fname3','VE','HE','RE','stimulus_str'}; % variable stringseditchannel_str={'editchannel1','editchannel2','editchannel3'}; popupmenu_str={'up_popupmenu','down_popupmenu','left_popupmenu','right_popupmenu','blink_popupmenu'};stimulus_val={'up_val','down_val','left_val','right_val','blink_val'}; for k=1:length(str)-1 if k<4 try set(prev_handles.(str{k}),'string',vars.(str{k})); % vars is the saved variable name catch end else try set(prev_handles.(editchannel_str{k-3}),'string',vars.(str{k})); catch end endendfor k=1:length(stimulus_val) try set(prev_handles.(popupmenu_str{k}),'String',vars.(str{7}),'Value',vars.(stimulus_val{k}),'Enable','on'); catch endendvar={'VE_init','HE_init','RE_init',... 'data','hdr','ch_label',... 'VE','HE','RE',... 'hdr_tbc','tbc_data','tbc_corrdata'... 'dataset','ve_count','he_count',... 're_count','fname1','fname2',... 'fname3','pathname1','pathname2',... 'pathname3','per','pathname1st2open','run_id',... 'tbc_num_blocks','stimulus_str','up_val','down_val',... 'left_val','right_val','blink_val',... 'prev_up_val','prev_down_val','prev_left_val',... 'prev_right_val','prev_blink_val','prev_VE',... 'prev_HE','prev_RE','prev_fname1',... 'prev_fname2','prev_fname3','plot_id','tbc_size'};for i=1:length(var) try if isempty(getappdata(hMainGui,var{i})) setappdata(hMainGui,var{i},vars.(var{i})); % must use the round bracket to access var{i} else rmappdata(hMainGui,var{i}); setappdata(hMainGui,var{i},vars.(var{i})); end catch endendstatusbar(prev_handles.figure1);% --- Executes on button press in newpushbutton.function newpushbutton_Callback(hObject, eventdata, handles)hMainGui = getappdata(0,'hMainGui'); var={'VE_init','HE_init','RE_init',... 'data','hdr','ch_label',... 'VE','HE','RE',... 'hdr_tbc','tbc_data','tbc_corrdata'... 'dataset','ve_count','he_count',... 're_count','fname1','fname2',... 'fname3','pathname1','pathname2',... 'pathname3','per','pathname1st2open','run_id',... 'tbc_num_blocks','stimulus_str','up_val','down_val',... 'left_val','right_val','blink_val',... 'prev_up_val','prev_down_val','prev_left_val',... 'prev_right_val','prev_blink_val','prev_VE',... 'prev_HE','prev_RE','prev_fname1',... 'prev_fname2','prev_fname3','plot_id','tbc_size',... 'pnt','plot_type','swp','type_tbc',... 'plot_type','range','tmax','display_length','starting_plot',... 'prev_dispval','prev_val','prev_epochval','prev_tlim','prev_tval_max',... 'prev_tval','prev_tmin','y_lim'}; % set the name of the variables that are going to be removed for i=1:length(var) if ~isempty(getappdata(hMainGui,var{i})) rmappdata(hMainGui,var{i}) % to remove the set variables. If the var is empty, then it will remain empty. endendstarting_id=1;run_id=0;setappdata(hMainGui,'run_id',run_id);setappdata(hMainGui,'starting_id',starting_id); set(handles.figure1,'Pointer','arrow'); % change the pointer back to arrow shapeset(handles.channel_checkbox,'Value',0); % untick the channel selection boxset(handles.channel_checkbox,'Enable','Inactive'); % disable the channel_checkbox handle% Set the stimulus code handlesset(handles.up_popupmenu,'Value',1,'String','Undefined','Enable','Inactive');set(handles.down_popupmenu,'Value',1,'String','Undefined','Enable','Inactive');set(handles.left_popupmenu,'Value',1,'String','Undefined','Enable','Inactive');set(handles.right_popupmenu,'Value',1,'String','Undefined','Enable','Inactive');set(handles.blink_popupmenu,'Value',1,'String','Undefined','Enable','Inactive');try statusbar(handles.figure1); % clear the statusbarcatchendinit_strings(handles); % to change back to the initial strings% --- Executes on button press in runpushbutton.function runpushbutton_Callback(hObject, eventdata, handles)warning off all; % Turn off all the warnings% Catch the error during the running of the programtry % 1a. Check if all files have been loaded statusbar(handles.figure1,'Program status: Please wait while running the program...'); hMainGui = getappdata(0,'hMainGui'); set(handles.figure1,'Pointer','watch'); keep('hMainGui','handles','hObject','eventdata'); if isequal('',get(handles.fname1,'string'))||... isequal('',get(handles.fname2,'string'))||... isequal('',get(handles.fname3,'string')) set(handles.figure1,'Pointer','arrow'); statusbar(handles.figure1); warn1=msgbox(' Please load all the files.','Warning','warn','modal'); % use return to return to the main Gui waitfor(warn1); % use waitfor to hold on other functions of the GUI until user press ok return end data=getappdata(hMainGui,'data'); % cnt data detect_const=0; VE_init=getappdata(hMainGui,'VE_init'); HE_init=getappdata(hMainGui,'HE_init'); RE_init=getappdata(hMainGui,'RE_init'); in{1}=strtrim(get(handles.editchannel1,'string')); in{2}=strtrim(get(handles.editchannel2,'string')); in{3}=strtrim(get(handles.editchannel3,'string')); ch_label=getappdata(hMainGui,'ch_label'); for i=1:length(ch_label) % create variables for each channel but only for 1 row of data. ch.(ch_label{i})=data(1:2,i); y=[ch_label{i},'=ch.',ch_label{i},';']; eval(y); end try for i=1:length(in) for j=1:length(in{i}) % converts to capital letters if in{i}(j)>=97 && in{i}(j)<=122 in{i}(j)=in{i}(j)-32; end end if isempty(eval(in{i})) % check whether it is an empty or const values error; elseif isscalar(eval(in{i})) detect_const=1; error; end end catch while(i<length(in)+1) try if isscalar(eval(in{i}))||isempty(eval(in{i})) % double check whether the field is empty or const values error; end catch switch(i) % correct field if it is error. case 1 set(handles.editchannel1,'string',VE_init); case 2 set(handles.editchannel2,'string',HE_init); case 3 set(handles.editchannel3,'string',RE_init); end end i=i+1; end if detect_const==1 string={' Invalid syntax for channel selections.' '' ' If the channels have numbers as labels:' '' 'Type in: "ch#", where "#" = the channel label' '' ' Example: ch2-ch3'}; set(handles.figure1,'Pointer','arrow'); statusbar(handles.figure1); warn2=msgbox(string,'Warning','warn','modal'); waitfor(warn2); return else set(handles.figure1,'Pointer','arrow'); statusbar(handles.figure1); warn3=msgbox(' Invalid channel selections.','Warning','warn','modal'); waitfor(warn3); return end end % 1b. Check whether there are any double selections on the stimulus_code stimulus_str=get(handles.up_popupmenu,'string'); up_val=get(handles.up_popupmenu,'value'); up_code=str2double(stimulus_str{up_val}); down_val=get(handles.down_popupmenu,'value'); down_code=str2double(stimulus_str{down_val}); left_val=get(handles.left_popupmenu,'value'); left_code=str2double(stimulus_str{left_val}); right_val=get(handles.right_popupmenu,'value'); right_code=str2double(stimulus_str{right_val}); blink_val=get(handles.blink_popupmenu,'value'); blink_code=str2double(stimulus_str{blink_val}); stimulus_code=[up_code; down_code; left_code; right_code; blink_code]; for codeidx=1:length(stimulus_code) if ~isnan(stimulus_code(codeidx)) rowidx=codeidx; for k=1:length(stimulus_code)-1 rowidx=rowidx+1; if rowidx>length(stimulus_code) rowidx=1; end if stimulus_code(codeidx)==stimulus_code(rowidx) str={'Multiple eye movement types have the same code.' '' ' Please check data and try again.'}; set(handles.figure1,'Pointer','arrow'); statusbar(handles.figure1); warn4=msgbox(str,'Warning','warn','modal'); waitfor(warn4); return end end else str={'"Five" eye movement types have not been defined.' '' ' Please check data and try again.'}; set(handles.figure1,'Pointer','arrow'); statusbar(handles.figure1); warn6=msgbox(str,'Warning','warn','modal'); waitfor(warn6); return end end % Setting the current settings for fnames, VE, HE, RE, and stimulus codes as previous values in hMainGui setappdata(hMainGui,'prev_fname1',get(handles.fname1,'string')); setappdata(hMainGui,'prev_fname2',get(handles.fname2,'string')); setappdata(hMainGui,'prev_fname3',get(handles.fname3,'string')); setappdata(hMainGui,'prev_VE',in{1}); setappdata(hMainGui,'prev_HE',in{2}); setappdata(hMainGui,'prev_RE',in{3}); setappdata(hMainGui,'prev_up_val',up_val); setappdata(hMainGui,'prev_down_val',down_val); setappdata(hMainGui,'prev_left_val',left_val); setappdata(hMainGui,'prev_right_val',right_val); setappdata(hMainGui,'prev_blink_val',blink_val); % 2. Separating channel labels and rate for eog file keep('hMainGui','data','ch_label','in','handles','hObject','eventdata','stimulus_code'); hdr=getappdata(hMainGui,'hdr'); dataset=getappdata(hMainGui,'dataset'); str=hdr{5,1}; % get line 5 of the header idx=strfind(str,']'); freq=str2num(strtrim(str((idx+1):end))); % freq of the signal per=1/freq; % T for period % --------- Additional ---------- setappdata(hMainGui,'per',per); % ------------------------------- % 3. Separating dataset to datapnts datapnts=round(dataset(:,6)); % check whether it is given in datapoints or time type=dataset(:,2); if ~isequal(datapnts,dataset(:,6)) datapnts=dataset(:,6)/T; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -