📄 main.m
字号:
end% Initialise the ve_count, he_count, re_count to empty valuessetappdata(hMainGui,'ve_count',[]);setappdata(hMainGui,'he_count',[]);setappdata(hMainGui,'re_count',[]);% Identify the VE channel selections through empty array checkingtry k=1; for i=1:length(vech) if ~isempty(vech{i}) switch(vech{i}) case 'E1' ch_idx(k)=1; case 'E2' ch_idx(k)=2; case 'E3' ch_idx(k)=3; case 'E4' ch_idx(k)=4; end idx(k)=i; k=k+1; end endcatchendtry if ischar(vech) set(handles.editchannel1,'string',vech); setappdata(hMainGui,'ve_count',ve_count); elseif length(idx)==2 if ch_idx(1)==1 && ch_idx(2)==3 ||... ch_idx(1)==2 && ch_idx(2)==4 set(handles.editchannel1,'string',[vech{idx(1)} '-' vech{idx(2)}]); end elseif length(idx)==3 if ch_idx(1)==1 && ch_idx(2)==3 ||... ch_idx(1)==2 && ch_idx(2)==4 set(handles.editchannel1,'string',[vech{idx(1)} '-' vech{idx(2)}]); elseif ch_idx(1)==1 && ch_idx(3)==3 ||... ch_idx(1)==2 && ch_idx(3)==4 set(handles.editchannel1,'string',[vech{idx(1)} '-' vech{idx(3)}]); elseif ch_idx(2)==1 && ch_idx(3)==3 ||... ch_idx(2)==2 && ch_idx(3)==4 set(handles.editchannel1,'string',[vech{idx(2)} '-' vech{idx(3)}]); end elseif length(idx)==4 set(handles.editchannel1,'string',['(' vech{1} '+' vech{2} '-' vech{3} '-' vech{4} ')/2']); endcatchend try if ischar(hech) set(handles.editchannel2,'string',hech); setappdata(hMainGui,'he_count',he_count); else set(handles.editchannel2,'string',[hech{1} '-' hech{2}]); endcatchendtry if ischar(rech) set(handles.editchannel3,'string',rech); setappdata(hMainGui,'re_count',re_count); elseif length(idx)==2 if ch_idx(1)==1 && ch_idx(2)==3 ||... ch_idx(1)==2 && ch_idx(2)==4 set(handles.editchannel3,'string',['(' rech{idx(1)} '+' rech{idx(2)} ')/2']); % average between the two channels for RE end elseif length(idx)==3 if ch_idx(1)==1 && ch_idx(2)==3 ||... ch_idx(1)==2 && ch_idx(2)==4 set(handles.editchannel3,'string',['(' rech{idx(1)} '+' rech{idx(2)} ')/2']); elseif ch_idx(1)==1 && ch_idx(3)==3 ||... ch_idx(1)==2 && ch_idx(3)==4 set(handles.editchannel3,'string',['(' rech{idx(1)} '+' rech{idx(3)} ')/2']); elseif ch_idx(2)==1 && ch_idx(3)==3 ||... ch_idx(2)==2 && ch_idx(3)==4 set(handles.editchannel3,'string',['(' rech{idx(2)} '+' rech{idx(3)} ')/2']); end elseif length(idx)==4 set(handles.editchannel3,'string',['(' rech{1} '+' rech{2} '+' rech{3} '+' rech{4} ')/4']); endcatchend set(handles.channel_checkbox,'Enable','on'); % Enable the channel checkboxsetappdata(hMainGui,'VE_init',get(handles.editchannel1,'string')); % assign as the VE, HE, RE initial channel selectionssetappdata(hMainGui,'HE_init',get(handles.editchannel2,'string'));setappdata(hMainGui,'RE_init',get(handles.editchannel3,'string'));setappdata(hMainGui,'VE',get(handles.editchannel1,'string')); % also assign as VE, HE, and RE channel selectionssetappdata(hMainGui,'HE',get(handles.editchannel2,'string'));setappdata(hMainGui,'RE',get(handles.editchannel3,'string'));setappdata(hMainGui,'pathname1st2open',pathname1st2open); % set the directory of the 1st file open to pathname1st2open% --- Executes on button press in loadpushbutton2.function loadpushbutton2_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui'); set(handles.up_popupmenu,'enable','on');set(handles.down_popupmenu,'enable','on');set(handles.left_popupmenu,'enable','on');set(handles.right_popupmenu,'enable','on');set(handles.blink_popupmenu,'enable','on');timeperchar=getappdata(hMainGui,'timeperchar');pathname0=getappdata(hMainGui,'pathname0'); % root directorypathname1=getappdata(hMainGui,'pathname1'); % eog calibration file directorypathname2=getappdata(hMainGui,'pathname2'); % eog datapnts file directorypathname3=getappdata(hMainGui,'pathname3'); % tbc directorypathname1st2open=getappdata(hMainGui,'pathname1st2open'); % directory when the 1st file is openif ~isempty(pathname1)&&isempty(pathname2)&&isempty(pathname3) cd(pathname1);elseif isempty(pathname1)&&~isempty(pathname2)&&isempty(pathname3) cd(pathname2); elseif isempty(pathname1)&&isempty(pathname2)&&~isempty(pathname3) cd(pathname3);elseif ~isempty(pathname1st2open) cd(pathname1st2open);endselect=1; invalid=1; data_type='datapnts';while (invalid==1) while(select~=0) [fname2, pathname2] = uigetfile('*.ev2', 'Pick "eog event" file'); if isempty(pathname1)&&isempty(pathname3) pathname1st2open=pathname2; end cd(pathname0); if isequal(fname2,0) || isequal(pathname2,0) return else select=0; invalid=0; end end try set(handles.figure1,'Pointer','watch'); [dataset,hdr_dataset]=read([pathname2 fname2],handles,timeperchar,data_type); % Reading dataset file set(handles.figure1,'Pointer','arrow'); catch statusbar(handles.figure1); set(handles.figure1,'Pointer','arrow'); warn_push2=msgbox('Please Select EOG Event File','Warning','warn','modal'); waitfor(warn_push2); select=1; invalid=1; endendsetappdata(hMainGui,'plot_id',0); % plot_id =0 -> cannot be plotted% Assigning the data types to the popupmenutype=dataset(:,2);stimulus=0; present=0; not_present=0;% Filtering the data typesfor colidx=1:length(type) for k=1:length(stimulus) if colidx==1 stimulus(1,1)=type(colidx); % Assign to type(colidx) to stimulus at the initialisation elseif ~isequal(stimulus(k),type(colidx)) not_present=1; elseif isequal(stimulus(k),type(colidx)) present=1; break; end end if not_present==1 && present==0 stimulus(end+1,1)=type(colidx); % Assign to stimulus only if it has not been present in the stimulus variable else not_present=0; % Reset the not_present and present variables present=0; endend% Sorting out the data types in ascending orderstimulus=sort(stimulus,'ascend');stimulus_str=cell(length(stimulus),1);stimulus_count=0;% Filter stimulus_code 1,2,3,4,5 and assign stimulus to stimulus_strfor k=1:length(stimulus) if stimulus(k)>0 && stimulus(k)<6 if isequal(stimulus(k),1) up_val=k; elseif isequal(stimulus(k),2) down_val=k; elseif isequal(stimulus(k),3) left_val=k; elseif isequal(stimulus(k),4) right_val=k; elseif isequal(stimulus(k),5) blink_val=k; end stimulus_count=stimulus_count+1; end stimulus_str{k,1}=num2str(stimulus(k));endstimulus_str{end+1,1}='Undefined';if ~isequal(stimulus_count,5) up_val=length(stimulus_str); down_val=up_val; left_val=up_val; right_val=up_val; blink_val=up_val;end% Assigning the stimlus_code to the popupmenuset(handles.up_popupmenu,'String',stimulus_str);set(handles.down_popupmenu,'String',stimulus_str);set(handles.left_popupmenu,'String',stimulus_str);set(handles.right_popupmenu,'String',stimulus_str);set(handles.blink_popupmenu,'String',stimulus_str);% Set the handles up, down, left, right, blink popupmenu to the defined valuesset(handles.up_popupmenu,'Value',up_val);set(handles.down_popupmenu,'Value',down_val);set(handles.left_popupmenu,'Value',left_val);set(handles.right_popupmenu,'Value',right_val);set(handles.blink_popupmenu,'Value',blink_val);set(handles.fname2,'string',fname2);setappdata(hMainGui,'fname2',fname2);setappdata(hMainGui,'pathname2',pathname2);setappdata(hMainGui,'dataset',dataset);setappdata(hMainGui,'pathname1st2open',pathname1st2open);setappdata(hMainGui,'stimulus_str',stimulus_str); setappdata(hMainGui,'up_val',up_val);setappdata(hMainGui,'down_val',down_val);setappdata(hMainGui,'left_val',left_val);setappdata(hMainGui,'right_val',right_val);setappdata(hMainGui,'blink_val',blink_val);% --- Executes on button press in loadpushbutton3.function loadpushbutton3_Callback(hObject, eventdata, handles)hMainGui=getappdata(0, 'hMainGui');timeperchar=getappdata(hMainGui,'timeperchar');pathname0=getappdata(hMainGui,'pathname0'); % root directorypathname1=getappdata(hMainGui,'pathname1'); % eog calibration file directorypathname2=getappdata(hMainGui,'pathname2'); % eog datapnts file directorypathname3=getappdata(hMainGui,'pathname3'); % tbc directorypathname1st2open=getappdata(hMainGui,'pathname1st2open'); % directory when the 1st file is openif ~isempty(pathname1)&&isempty(pathname2)&&isempty(pathname3) cd(pathname1);elseif isempty(pathname1)&&~isempty(pathname2)&&isempty(pathname3) cd(pathname2);elseif isempty(pathname1)&&isempty(pathname2)&&~isempty(pathname3) cd(pathname3);elseif ~isempty(pathname1st2open) cd(pathname1st2open);endselect=1; invalid=1; data_type='tbc';while (invalid==1) while(select~=0) [fname3, pathname3] = uigetfile('*.dat', 'Pick "to-be-corrected" file'); if isempty(pathname1)&&isempty(pathname2) pathname1st2open=pathname3; end cd(pathname0); if isequal(fname3,0) || isequal(pathname3,0) return else select=0; invalid=0; end end try set(handles.figure1,'Pointer','watch'); [tbc_data,hdr_tbc,tbc_num_blocks]=read([pathname3 fname3],handles,timeperchar,data_type); % Reading TBC file set(handles.figure1,'Pointer','arrow'); catch statusbar(handles.figure1); set(handles.figure1,'Pointer','arrow'); warn_push3=msgbox('Please Select To-Be-Corrected Data File','Warning','warn','modal'); waitfor(warn_push3); select=1; invalid=1; endendsetappdata(hMainGui,'plot_id',0); % plot_id =0 -> cannot be plottedset(handles.fname3,'string',fname3);setappdata(hMainGui,'fname3',fname3); setappdata(hMainGui,'pathname3',pathname3);setappdata(hMainGui,'hdr_tbc',hdr_tbc); setappdata(hMainGui,'tbc_data',tbc_data);setappdata(hMainGui,'pathname1st2open',pathname1st2open);setappdata(hMainGui,'tbc_num_blocks',tbc_num_blocks);% ------------------------------------------------------% Edit Text for Channel Selections Callback% -------------------------------------------------------function editchannel1_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui');setappdata(hMainGui,'VE',get(hObject,'string')); % assign the string to the hMainGui data% --- Executes during object creation, after setting all properties. All of the createfcn are for the initialisation. function editchannel1_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction editchannel2_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui');setappdata(hMainGui,'HE',get(hObject,'string')); % --- Executes during object creation, after setting all properties.function editchannel2_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction editchannel3_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui');setappdata(hMainGui,'RE',get(hObject,'string'));% --- Executes during object creation, after setting all properties.function editchannel3_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% ----------------------------------------% Check box% ----------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -