⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.m

📁 EOG Correction program is used to work out the amount of ocular potential recorded by the electroenc
💻 M
📖 第 1 页 / 共 5 页
字号:
    setappdata(hMainGui,'tbc_size',tbc_size);        % ----------- Additional ---------------------        hdr_tbc=getappdata(hMainGui,'hdr_tbc');        type_tbc=hdr_tbc{6,1};    idx=strfind(type_tbc,']');    type_tbc=strtrim(type_tbc((idx+1):end));    setappdata(hMainGui,'type_tbc',type_tbc);        if strcmp(type_tbc,'Continuous')        pnt=tbc_size;        swp=1;    elseif strcmp(type_tbc,'Average')        strpnt=hdr_tbc{7,1};        idx=strfind(strpnt,']');        pnt=str2num(strtrim(strpnt((idx+1):end)));        setappdata(hMainGui,'pnt',pnt);        swp=2;    elseif strcmp(type_tbc,'Epoch')        strpnt=hdr_tbc{8,1};        idx=strfind(strpnt,']');        pnt=str2num(strtrim(strpnt((idx+1):end)));        setappdata(hMainGui,'pnt',pnt);        swp=hdr_tbc{10,1};        idx=strfind(swp,']');        swp=str2num(strtrim(swp((idx+1):end)));        setappdata(hMainGui,'swp',swp);    end    % Removing the mean    tbc_avg=zeros(colsize,swp);       rowstart=1;    for n=1:swp        rowend=rowstart+(pnt-1);        for k=1:colsize                        try                tbc_data(rowstart:rowend,k)=tbc_data(rowstart:rowend,k)-mean(tbc_data(rowstart:rowend,k));            catch                tbc_data(rowstart:end,k)=tbc_data(rowstart:end,k)-mean(tbc_data(rowstart:end,k));                          end        end        if n~=swp            rowstart=rowend+2;        end    end        setappdata(hMainGui,'tbc_data',tbc_data);   % Assign the new tbc_data with the mean taken off to hMainGui    % ------------------------------------        tbc_num_blocks=getappdata(hMainGui,'tbc_num_blocks');            if tbc_num_blocks>1        row_size=ceil(tbc_size/tbc_num_blocks);    else        row_size=tbc_size;    end    row_start=1;    for block=1:tbc_num_blocks        row_end=(row_start-1)+row_size;        if row_end>tbc_size            row_end=tbc_size;        end        for i=1:length(ch_label)            ch.(ch_label{i})=tbc_data(row_start:row_end,i);            y=[ch_label{i},'(row_start:row_end,1)=ch.',ch_label{i},';'];            eval(y);        end        if block~=tbc_num_blocks            row_start=row_end+1;        end    end        VE=zeros(tbc_size,1); HE=VE; RE=VE; % Pre-allocation with zeros        VE=eval(in{1});    HE=eval(in{2});    RE=eval(in{3});        keep('hMainGui','handles','avg_count','ch_label','Bv','Bh','Br','tbc_data','VE','HE','RE',...        'tbc_num_blocks','tbc_size','row_size','colsize','hObject','eventdata','hdr_tbc');        ve_count=getappdata(hMainGui,'ve_count');    he_count=getappdata(hMainGui,'he_count');    re_count=getappdata(hMainGui,'re_count');          %% 2. Perform 1st half correction using the computed Bv and Bh    % $$corrdata=data-\beta_v*VE-\beta_h*HE$$        % Pre-allocation for tbc_corrdata        row_start=1;    for block=1:tbc_num_blocks        row_end=(row_start-1)+row_size;        if row_end>tbc_size            row_end=tbc_size;        end        tbc_corrdata(row_start:row_end,1:colsize)=zeros(row_end-(row_start-1),colsize,'single');                if block~=tbc_num_blocks            row_start=row_end+1;        end    end        colsize=colsize+1;      % Increase the colsize by 1 to accomodate RE channel correction      row_start=1;    for block=1:tbc_num_blocks        row_end=(row_start-1)+row_size;        if row_end>tbc_size            row_end=tbc_size;        end        for colidx=1:colsize            if colidx~=colsize                workbar((colidx+(block-1)*colsize)/(colsize*tbc_num_blocks),'Step 2 of 4...','Program Status');                if ~isequal(colidx,ve_count)&&~isequal(colidx,he_count)&&~isequal(colidx,re_count)                    tbc_corrdata(row_start:row_end,colidx)=tbc_data(row_start:row_end,colidx)-VE(row_start:row_end)*Bv(colidx)-HE(row_start:row_end)*Bh(colidx); % 1st half of correction                else                    tbc_corrdata(row_start:row_end,colidx)=tbc_data(row_start:row_end,colidx);                end            else                workbar((colidx+(block-1)*colsize)/(colsize*tbc_num_blocks),'Step 2 of 4...','Program Status');                RE(row_start:row_end,1)=RE(row_start:row_end,1)-VE(row_start:row_end)*Bv(colidx)-HE(row_start:row_end)*Bh(colidx);  % RE channel still needs to be corrected for all cases            end        end        if block~=tbc_num_blocks            row_start=row_end+1;                   end    end      %% 3. Perform 2nd half correction using the computed Br    % $$corrdata2=corrdata-\beta_r*RE$$    try        if ~isempty(Br)            keep('hMainGui','handles','avg_count','ch_label','Bv','Bh','Br','RE','tbc_corrdata',...                'tbc_num_blocks','tbc_size','row_size','colsize','ve_count','he_count','re_count','hObject','eventdata','hdr_tbc');            colsize=colsize-1;  % reduce colsize by 1 so colsize = length(ch_label)            row_start=1;            for block=1:tbc_num_blocks                row_end=(row_start-1)+row_size;                if row_end>tbc_size                    row_end=tbc_size;                end                for colidx=1:colsize                    workbar((colidx+(block-1)*colsize)/(colsize*tbc_num_blocks),'Step 3 of 4...','Program Status');                    if ~isequal(colidx,ve_count)&&~isequal(colidx,he_count)&&~isequal(colidx,re_count)                        tbc_corrdata(row_start:row_end,colidx)=tbc_corrdata(row_start:row_end,colidx)-RE(row_start:row_end)*Br(colidx); % 1st half of correction                    end                end                if block~=tbc_num_blocks                    row_start=row_end+1;                end            end        end    catch    end    setappdata(hMainGui,'tbc_corrdata',tbc_corrdata);        %% V. Title: Writing output .dat file of TBC data    keep('hMainGui','handles','avg_count','ch_label','Bv','Bh','Br','tbc_corrdata','hObject','eventdata','hdr_tbc');        pathname1=getappdata(hMainGui,'pathname1');     % pathname1 is the eog calibration dir    pathname0=getappdata(hMainGui,'pathname0');     % pathname0 is the root/ program dir               % Get the data from the hMainGui    tbc_fname=getappdata(hMainGui,'fname3');        % Assign the tbc_fname file    idx=strfind(tbc_fname,'.');    tbc_fname=strtrim(tbc_fname(1:(idx-1)));    fname=[tbc_fname '_c'];     % fname to check            % Check the existence of the file in the directory    exist_id=exist([pathname1 fname '.dat'],'file');    if exist_id==2        button = questdlg('Do you want to overwrite the file?','Exit Dialog','Yes','No','No');        if strcmp(button,'No')            fname_id='0';            while exist_id==2                fname_id=num2str(str2double(fname_id)+1);                exist_id=exist([tbc_fname '_c_' fname_id '.dat'],'file');            end            fname=[tbc_fname '_c_' fname_id];        end    end        % Write the corrected data    fid=fopen([pathname1 fname '.dat'],'wt');        [rownum,colnum]=size(hdr_tbc);    dataidx=1;    data_end=size(tbc_corrdata,1);        for colidx=1:colnum        % read the header line per line        for rowidx=1:rownum            if ~isempty(hdr_tbc{rowidx,colidx})                fprintf(fid,'%s\n',hdr_tbc{rowidx,colidx});   % fid=1, to output to screen            end        end        % read and write the data line per line.        while dataidx<=data_end            workbar(dataidx/data_end,'Step 4 of 4...','Program Status');            if ~isnan(tbc_corrdata(dataidx,:))                fprintf(fid,'%s\n',sprintf('%11.2E\t',tbc_corrdata(dataidx,:)));    % for exponential output format. tab delimiter. convert data to str. if using dlmwrite - cannot be formatted as using sprintf.                dataidx=dataidx+1;            else                dataidx=dataidx+1;                break            end        end    end    fclose(fid);            % Exit the workbar if dataidx<data_end    if dataidx<data_end        dataidx=data_end;        workbar(dataidx/data_end,'Step 4 of 4...','Program Status');    end      %% VI. Title: Writing Bv, Bh, and Br output .dat file    keep('hMainGui','handles','avg_count','ch_label','Bv','Bh','Br','pathname1','pathname0','fname','hObject','eventdata');        fid=fopen([pathname1 fname '_coefficients.dat'],'wt');    ch_label=[ch_label;'RE'];    if length(avg_count)==5        Br=[Br 1];  % 1 is Br for channel RE        b=[Bv' Bh' Br'];        hdr_corr{1}='Labels';        hdr_corr{2}='Bv';        hdr_corr{3}='Bh';        hdr_corr{4}='Br';    else        b=[Bv' Bh'];        hdr_corr{1}='Labels';        hdr_corr{2}='Bv';        hdr_corr{3}='Bh';    end    for k=1:length(hdr_corr)        if k<length(hdr_corr)            fprintf(fid,'%8s\t',hdr_corr{k});        else            fprintf(fid,'%8s\n',hdr_corr{k});        end    end    for p=1:length(ch_label)        fprintf(fid,'%8s\t',ch_label{p});        dstr=sprintf('%8.4f\t',b(p,:));    % tab delimiter        fprintf(fid,'%s\n',dstr);    end    fclose(fid);    set(handles.figure1,'Pointer','arrow');                % VII. Conclusion: saving and msg dialog box    keep('hMainGui','handles','pathname1','pathname0','hObject','eventdata');        % set the run_id to indicate that the run_pushbutton has been pressed    run_id=1;    setappdata(hMainGui,'run_id',run_id);         starting_id=0;    setappdata(hMainGui,'starting_id',starting_id);          button = questdlg('Would you like to save the settings?','RAAA','Yes','No','No');    switch button        case 'Yes'            statusbar(handles.figure1, 'Program status: Please wait while saving the settings...');            Save_Callback(hObject, eventdata, handles);            statusbar(handles.figure1);        case 'No'    end    statusbar(handles.figure1);        string={'                  Finished !'        ''        '     Your Data Has Now Been'        ''        '             EOG-Corrected'};    msg1=msgbox(string,'RAAA','modal');    waitfor(msg1);catch    err=lasterror;    if strcmp(err.identifier,'MATLAB:nomem')        string={'                         Out of Memory.'        ''        '  Please close other applications and re-run the program.'};    else        string={'            Invalid files.'            ''            '  Please reload all the files.'};        clearpushbutton_Callback(hObject, eventdata, handles);    end    set(handles.figure1,'Pointer','arrow');    statusbar(handles.figure1);        clearpushbutton_Callback(hObject, eventdata, handles);      warn5=msgbox(string,'Warning','warn','modal');   % use return to return to the main Gui    waitfor(warn5);     % use waitfor to hold on other functions of the GUI until user press ok        returnend% --- Executes on button press in plotpushbutton.function plotpushbutton_Callback(hObject, eventdata, handles)hMainGui = getappdata(0, 'hMainGui'); run_id=getappdata(hMainGui,'run_id');starting_id=getappdata(hMainGui,'starting_id');prev_VE=getappdata(hMainGui,'prev_VE');prev_HE=getappdata(hMainGui,'prev_HE');prev_RE=getappdata(hMainGui,'prev_RE');in{1}=strtrim(get(handles.editchannel1,'string'));in{2}=strtrim(get(handles.editchannel2,'string'));in{3}=strtrim(get(handles.editchannel3,'string'));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    endendprev_up_val=getappdata(hMainGui,'prev_up_val');prev_down_val=getappdata(hMainGui,'prev_down_val');prev_left_val=getappdata(hMainGui,'prev_left_val');prev_right_val=getappdata(hMainGui,'prev_right_val');prev_blink_val=getappdata(hMainGui,'prev_blink_val');up_val=getappdata(hMainGui,'up_val');down_val=getappdata(hMainGui,'down_val');left_val=getappdata(h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -