📄 eegplot.m
字号:
spacing = spacing + .05*orgspacing; % increase spacing (5%) elseif p1 == 2 spacing = max(0,spacing-.05*orgspacing); % decrease spacing (5%) if spacing == 0 spacing = spacing + .05*orgspacing; end end set(ESpacing,'string',num2str(spacing,4)) % update edit box % plot data and update axes meandata = mean(data(:,round(time*Fs+1):round(min((time+winlength)*Fs,... frames)))'); axes(ax1) cla for i = 1:chans plot(data(chans-i+1,... round(time*Fs+1):round(min((time+winlength)*Fs,... frames)))-meandata(chans-i+1)+i*spacing,... 'color',DEFAULT_PLOT_COLOR,'clipping','off') end set(ax1,'YLim',[0 (chans+1)*spacing],... 'YTick',[0:spacing:chans*spacing]) % update scaling eye if it exists eyeaxes = findobj('tag','eyeaxes','parent',figh); if ~isempty(eyeaxes) eyetext = findobj('type','text','parent',eyeaxes,'tag','thescale'); set(eyetext,'string',num2str(spacing,4)) end case 'window' % get new window length with dialog box fig = gcbf; oldwinlen = get(fig,'UserData'); pos = get(fig,'Position'); figx = 400; figy = 200; fhand = figure('Units','pixels',... 'Position',... [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],... 'Resize','off','CloseRequestFcn','','menubar','none',... 'numbertitle','off','tag','dialog','userdata',fig); uicolor = get(fhand,'Color'); uicontrol('Style','Text','Units','Pixels',... 'String','Enter new window length(secs):',... 'Position',[20 figy-40 300 25],'HorizontalAlignment','left',... 'BackgroundColor',uicolor,'FontSize',14) timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0);',... 'WLEN = str2num(get(OBJ1,''String''));',... 'if ~isempty(WLEN);',... 'UDATA = get(FIH0,''UserData'');',... 'UDATA(1) = WLEN;',... 'set(FIH0,''UserData'',UDATA);',... 'eegplot(''drawp'',0);',... 'delete(FIGH1);',... 'end;',... 'clear OBJ1 FIGH1 FIH0 AXH0 WLEN UDATA;']; ui1 = uicontrol('Style','Edit','Units','Pixels',... 'FontSize',12,... 'Position',[120 figy-100 70 30],... 'Callback',timestring,'UserData',fig,... 'String',num2str(oldwinlen(1))); timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0(1));',... 'SRAT = str2num(get(FIH0(2),''String''));',... 'if ~isempty(SRAT);',... 'UDATA = get(FIH0(1),''UserData'');',... 'UDATA(2) = SRAT;',... 'set(FIH0(1),''UserData'',UDATA);',... 'eegplot(''drawp'',0);',... 'delete(FIGH1);',... 'end;',... 'clear OBJ1 FIGH1 FIH0 AXH0 SRAT UDATA;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','OK','FontSize',14,... 'Position',[figx/4-20 10 65 30],... 'Callback',timestring,'UserData',[fig,ui1]) TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',... 'delete(FIGH1);',... 'clear OBJ1 FIGH1;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','Cancel','FontSize',14,... 'Position',[3*figx/4-20 10 65 30],... 'Callback',TIMESTRING) case 'samplerate' % Get new samplerate fig = gcbf; oldsrate = get(fig,'UserData'); pos = get(fig,'Position'); figx = 400; figy = 200; fhand = figure('Units','pixels',... 'Position',... [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],... 'Resize','off','CloseRequestFcn','','menubar','none',... 'numbertitle','off','tag','dialog','userdata',fig); uicolor = get(fhand,'Color'); uicontrol('Style','Text','Units','Pixels',... 'String','Enter new samplerate:',... 'Position',[20 figy-40 300 25],'HorizontalAlignment','left',... 'BackgroundColor',uicolor,'FontSize',14) timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0);',... 'SRAT = str2num(get(OBJ1,''String''));',... 'if ~isempty(SRAT);',... 'UDATA = get(FIH0,''UserData'');',... 'UDATA(2) = SRAT;',... 'set(FIH0,''UserData'',UDATA);',... 'eegplot(''drawp'',0);',... 'delete(FIGH1);',... 'end;',... 'clear OBJ1 FIGH1 FIH0 AXH0 SRAT UDATA;']; ui1 = uicontrol('Style','Edit','Units','Pixels',... 'FontSize',12,... 'Position',[120 figy-100 70 30],... 'Callback',timestring,'UserData',fig,... 'String',num2str(oldsrate(2))); timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0(1));',... 'SRAT = str2num(get(FIH0(2),''String''));',... 'if ~isempty(SRAT);',... 'UDATA = get(FIH0(1),''UserData'');',... 'UDATA(2) = SRAT;',... 'set(FIH0(1),''UserData'',UDATA);',... 'eegplot(''drawp'',0);',... 'delete(FIGH1);',... 'end;',... 'clear OBJ1 FIGH1 FIH0 AXH0 SRAT UDATA;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','OK','FontSize',14,... 'Position',[figx/4-20 10 65 30],... 'Callback',timestring,'UserData',[fig,ui1]) TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',... 'delete(FIGH1);',... 'clear OBJ1 FIGH1;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','Cancel','FontSize',14,... 'Position',[3*figx/4-20 10 65 30],... 'Callback',TIMESTRING) case 'loadelect' % load electrode file fig = gcbf; pos = get(fig,'Position'); figx = 400; figy = 200; fhand = figure('Units','pixels',... 'Position',... [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],... 'Resize','off','CloseRequestFcn','','menubar','none',... 'numbertitle','off','tag','dialog','userdata',fig); uicolor = get(fhand,'Color'); uicontrol('Style','Text','Units','Pixels',... 'String','Enter electrode file name:',... 'Position',[20 figy-40 300 25],'HorizontalAlignment','left',... 'BackgroundColor',uicolor,'FontSize',14) ui1 = uicontrol('Style','Edit','Units','Pixels',... 'FontSize',12,... 'HorizontalAlignment','left',... 'Position',[120 figy-100 210 30],... 'UserData',fig,'tag','electedit'); TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',... 'delete(FIGH1);',... 'clear OBJ1 FIGH1;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','Cancel','FontSize',14,... 'Position',[3*figx/4-20 10 65 30],... 'Callback',TIMESTRING) timestring = ['[OBJ1,FIGH1] = gcbo;',... 'OBJ2 = findobj(''tag'',''electedit'');',... 'LAB1 = get(OBJ2,''string'');',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0);',... 'OUT1 = eegplot(''setelect'',LAB1,AXH0);',... 'if (OUT1);',... 'delete(FIGH1);',... 'end;',... 'clear OBJ1 FIGH1 LAB1 OBJ2 FIH0 AXH0 OUT1;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','OK','FontSize',14,... 'Position',[figx/4-20 10 65 30],... 'Callback',timestring,'UserData',fig) timestring = ['OBJ2 = findobj(''tag'',''electedit'');',... '[LAB1,LAB2] = uigetfile(''*'',''Electrode File'');',... 'if (isstr(LAB1) & isstr(LAB2));',... 'set(OBJ2,''string'',[LAB2,LAB1]);',... 'end;',... 'clear OBJ2 LAB1 LAB2;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','Browse','FontSize',14,... 'Position',[figx/2-20 10 65 30],'UserData',fig,... 'Callback',timestring) case 'setelect' % Set electrodes eloc_file = p1; axeshand = p2; outvar1 = 1; if isempty(eloc_file) outvar1 = 0; return end fid = fopen(eloc_file); if fid < 1 fprintf('Cannot open electrode file.\n\n') outvar1 = 0; return end YLabels = fscanf(fid,'%d %f %f %s',[7 128]); if isempty(YLabels) fprintf('Error reading electrode file.\n\n') outvar1 = 0; return end fclose(fid); YLabels = char(YLabels(4:7,:)'); ii = find(YLabels == '.'); YLabels(ii) = ' '; YLabels = flipud(str2mat(YLabels,' ')); set(axeshand,'YTickLabel',YLabels) case 'title' % Get new title fig = gcbf; % oldsrate = get(fig,'UserData'); eegaxis = findobj('tag','eegaxis','parent',fig); oldtitle = get(eegaxis,'title'); oldtitle = get(oldtitle,'string'); pos = get(fig,'Position'); figx = 400; figy = 200; fhand = figure('Units','pixels',... 'Position',... [pos(1)+pos(3)/2-figx/2 pos(2)+pos(4)/2-figy/2 figx figy],... 'Resize','off','CloseRequestFcn','','menubar','none',... 'numbertitle','off','tag','dialog','userdata',fig); uicolor = get(fhand,'Color'); uicontrol('Style','Text','Units','Pixels',... 'String','Enter new title:',... 'Position',[20 figy-40 300 25],'HorizontalAlignment','left',... 'BackgroundColor',uicolor,'FontSize',14) timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0);',... 'SRAT = get(OBJ1,''String'');',... 'AXTH0 = get(AXH0,''title'');',... 'if ~isempty(SRAT);',... 'set(AXTH0,''string'',SRAT);',... 'end;',... 'delete(FIGH1);',... 'clear OBJ1 AXTH0 FIGH1 FIH0 AXH0 SRAT UDATA;']; ui1 = uicontrol('Style','Edit','Units','Pixels',... 'FontSize',12,... 'Position',[120 figy-100 3*70 30],... 'Callback',timestring,'UserData',fig,... 'String',oldtitle); timestring = ['[OBJ1,FIGH1] = gcbo;',... 'FIH0 = get(OBJ1,''UserData'');',... 'AXH0 = findobj(''tag'',''eegaxis'',''parent'',FIH0(1));',... 'SRAT = get(FIH0(2),''String'');',... 'AXTH0 = get(AXH0,''title'');',... 'set(AXTH0,''string'',SRAT);',... 'delete(FIGH1);',... 'clear OBJ1 AXTH0 FIGH1 FIH0 AXH0 SRAT UDATA;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','OK','FontSize',14,... 'Position',[figx/4-20 10 65 30],... 'Callback',timestring,'UserData',[fig,ui1]) TIMESTRING = ['[OBJ1,FIGH1] = gcbo;',... 'delete(FIGH1);',... 'clear OBJ1 FIGH1;']; uicontrol('Style','PushButton','Units','Pixels',... 'String','Cancel','FontSize',14,... 'Position',[3*figx/4-20 10 65 30],... 'Callback',TIMESTRING) case 'scaleeye' % Turn scale I on/off obj = p1; figh = p2; % figh = get(obj,'Parent'); toggle = get(obj,'checked'); if strcmp(toggle,'on') eyeaxes = findobj('tag','eyeaxes','parent',figh); children = get(eyeaxes,'children'); delete(children) set(obj,'checked','off') elseif strcmp(toggle,'off') eyeaxes = findobj('tag','eyeaxes','parent',figh); ESpacing = findobj('tag','ESpacing','parent',figh); spacing = str2num(get(ESpacing,'string')); axes(eyeaxes) YLim = get(eyeaxes,'Ylim'); Xl = [.35 .65 .5 .5 .35 .65]; Yl = [spacing*2 spacing*2 spacing*2 spacing*1 spacing*1 spacing*1]; line(Xl,Yl,'color',DEFAULT_AXIS_COLOR,'clipping','off',... 'tag','eyeline') text(.5,YLim(2)/23+Yl(1),num2str(spacing,4),... 'HorizontalAlignment','center','FontSize',10,... 'tag','thescale') if strcmp(YAXIS_NEG,'off') text(Xl(2)+.1,Yl(1),'+','HorizontalAlignment','left',... 'verticalalignment','middle') text(Xl(2)+.1,Yl(4),'-','HorizontalAlignment','left',... 'verticalalignment','middle') else text(Xl(2)+.1,Yl(4),'+','HorizontalAlignment','left',... 'verticalalignment','middle') text(Xl(2)+.1,Yl(1),'-','HorizontalAlignment','left',... 'verticalalignment','middle') end if ~isempty(SPACING_UNITS_STRING) text(.5,-YLim(2)/23+Yl(4),SPACING_UNITS_STRING,... 'HorizontalAlignment','center','FontSize',10) end set(obj,'checked','on') end case 'noui' % Plott EEG without ui controls data = p1; % usage: eegplot(data,Fs,spacing,eloc_file,startpoint,color) [chans,frames] = size(data); nargs = nargin; if nargs < 7 plotcolor = 0; else plotcolor = p6; end if nargs < 6 starts = 0; else starts = p5; end if nargs < 5 eloc_file = DEFAULT_ELOC_FILE; else eloc_file = p4; end if nargs < 4 spacing = 0; else spacing = p3; end if nargs < 3 Fs = 0; else Fs = p2; end if isempty(plotcolor) plotcolor = 0; end if isempty(spacing) spacing = 0; end if isempty(Fs) Fs = 0; end if isempty(starts) starts = 0; end if spacing == 0 spacing = max(max(data')-min(data')); end if Fs == 0 Fs = DEFAULT_SAMPLE_RATE; end range = floor(frames/Fs); axhandle = gca; if plotcolor == 0 if DEFAULT_NOUI_PLOT_COLOR == 0 colorord = get(axhandle,'ColorOrder'); plotcolor = colorord(1,:); else plotcolor = DEFAULT_NOUI_PLOT_COLOR; end end if ~isempty(eloc_file) if eloc_file == 0 YLabels = num2str((1:chans)'); else fid = fopen(eloc_file); if fid < 1 error('error opening electrode file') end YLabels = fscanf(fid,'%d %f %f %s',[7 128]); fclose(fid); YLabels = char(YLabels(4:7,:)'); ii = find(YLabels == '.'); YLabels(ii) = ' '; end YLabels = flipud(str2mat(YLabels,' ')); else YLabels = []; end set(axhandle,'xgrid','on','GridLineStyle','-',... 'Box','on','YTickLabel',YLabels,... 'ytick',[0:spacing:chans*spacing],... 'Ylim',[0 (chans+1)*spacing],... 'xtick',[0:Fs:range*Fs],... 'Xlim',[0 frames],... 'XTickLabel',num2str((0:1:range)'+starts)) meandata = mean(data'); axes(axhandle) hold on for i = 1:chans plot(data(chans-i+1,:)-meandata(chans-i+1)+i*spacing,'color',plotcolor) end otherwise error(['Error - invalid eegplot parameter: ',data]) end end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -