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

📄 eegplot.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 5 页
字号:
% End Main Function% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%else  try, p1 = varargin{1}; p2 = varargin{2}; p3 = varargin{3}; catch, end;  switch data  case 'drawp' % Redraw EEG and change position    % this test help to couple eegplot windows    if exist('p3')    	figh = p3;    	figure(p3);    else	    	figh = gcf;                          % figure handle	end;	    if strcmp(get(figh,'tag'),'dialog')      figh = get(figh,'UserData');    end    ax0 = findobj('tag','backeeg','parent',figh); % axes handle    ax1 = findobj('tag','eegaxis','parent',figh); % axes handle    g = get(figh,'UserData');    data = get(ax1,'UserData');    ESpacing = findobj('tag','ESpacing','parent',figh);   % ui handle    EPosition = findobj('tag','EPosition','parent',figh); % ui handle    if g.trialstag(1) == -1        g.time    = str2num(get(EPosition,'string'));      else         g.time    = str2num(get(EPosition,'string'));        g.time    = g.time - 1;    end;     g.spacing = str2num(get(ESpacing,'string'));            if p1 == 1      g.time = g.time-g.winlength;     % << subtract one window length    elseif p1 == 2                     g.time = g.time-fastif(g.winlength>=1, 1, g.winlength/5);             % < subtract one second    elseif p1 == 3      g.time = g.time+fastif(g.winlength>=1, 1, g.winlength/5);             % > add one second    elseif p1 == 4      g.time = g.time+g.winlength;     % >> add one window length    end    	 if g.trialstag ~= -1 % time in second or in trials		multiplier = g.trialstag;		 else		multiplier = g.srate;	 end;		        % Update edit box    % ---------------    g.time = max(0,min(g.time,ceil((g.frames-1)/multiplier)-g.winlength));    if g.trialstag(1) == -1        set(EPosition,'string',num2str(g.time));     else         set(EPosition,'string',num2str(g.time+1));     end;     set(figh, 'userdata', g);    lowlim = round(g.time*multiplier+1);    highlim = round(min((g.time+g.winlength)*multiplier+2,g.frames));        % Plot data and update axes    % -------------------------    switch lower(g.submean) % subtract the mean ?     case 'on', meandata = mean(data(:,lowlim:highlim)');       case 'nan',meandata = nan_mean(data(:,lowlim:highlim)');     otherwise, meandata = zeros(1,g.chans);    end;    axes(ax1)    cla         % plot data    % ---------    axes(ax1)    hold on    for i = 1:g.chans        plot(data(g.chans-i+1,lowlim:highlim) -meandata(g.chans-i+1)+i*g.spacing, ...             'color', g.color{mod(i-1,length(g.color))+1}, 'clipping','on')    end         % draw selected channels    % ------------------------    if ~isempty(g.winrej)    	for tpmi = 1:size(g.winrej,1) % scan rows			if (g.winrej(tpmi,1) >= lowlim & g.winrej(tpmi,1) <= highlim) | ...				(g.winrej(tpmi,2) >= lowlim & g.winrej(tpmi,2) <= highlim)				abscmin = max(1,round(g.winrej(tpmi,1)-lowlim));	 				abscmax = round(g.winrej(tpmi,2)-lowlim);				maxXlim = get(gca, 'xlim');				abscmax = min(abscmax, round(maxXlim(2)-1));	    				for i = 1:g.chans   					if g.winrej(tpmi,g.chans-i+1+5)   						plot(abscmin+1:abscmax+1,data(g.chans-i+1,abscmin+lowlim:abscmax+lowlim) ...   							-meandata(g.chans-i+1)+i*g.spacing, 'color','r','clipping','on')					end;    			end  			end;	    	end;    end;		        set(ax1, 'Xlim',[1 g.winlength*multiplier+1],...		     'XTick',[1:multiplier*DEFAULT_GRID_SPACING:g.winlength*multiplier+1]);    set(ax1, 'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'))    % ordinates: even if all elec are plotted, some may be hidden    set(ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );    eegplot('drawb');		 if g.children ~= 0		if ~exist('p2')			p2 =[];		end;			eegplot( 'drawp', p1, p2, g.children);		figure(figh);	 end;	      case 'drawb' % Draw background ******************************************************    % Redraw EEG and change position    ax0 = findobj('tag','backeeg','parent',gcf); % axes handle    ax1 = findobj('tag','eegaxis','parent',gcf); % axes handle            g = get(gcf,'UserData');  % Data (Note: this could also be global)    % Plot data and update axes    axes(ax0);	cla;	hold on;	% plot rejected windows	if g.trialstag ~= -1		multiplier = g.trialstag;		else		multiplier = g.srate;	end;		    % draw rejection windows    % ----------------------   	    lowlim = round(g.time*multiplier+1);   	highlim = round(min((g.time+g.winlength)*multiplier+1));  	displaymenu = findobj('tag','displaymenu','parent',gcf);    if ~isempty(g.winrej) & g.winstatus		if g.trialstag ~= -1 % epoched data			indices = find((g.winrej(:,1)' >= lowlim & g.winrej(:,1)' <= highlim) | ...						   (g.winrej(:,2)' >= lowlim & g.winrej(:,2)' <= highlim));			if ~isempty(indices)				tmpwins1 = g.winrej(indices,1)';				tmpwins2 = g.winrej(indices,2)';				tmpcols  = g.winrej(indices,3:5);				try, eval('[cumul indicescount] = histc(tmpwins1, (min(tmpwins1)-1):g.trialstag:max(tmpwins2));');				catch, [cumul indicescount] = myhistc(tmpwins1, (min(tmpwins1)-1):g.trialstag:max(tmpwins2));				end;				count = zeros(size(cumul));				%if ~isempty(find(cumul > 1)), find(cumul > 1), end;                for tmpi = 1:length(tmpwins1)					poscumul = indicescount(tmpi);					heightbeg = count(poscumul)/cumul(poscumul);					heightend = heightbeg + 1/cumul(poscumul);					count(poscumul) = count(poscumul)+1;					h = patch([tmpwins1(tmpi)-lowlim tmpwins2(tmpi)-lowlim ...							   tmpwins2(tmpi)-lowlim tmpwins1(tmpi)-lowlim], ...							  [heightbeg heightbeg heightend heightend], ...							  tmpcols(tmpi,:));  % this argument is color					set(h, 'EdgeColor', get(h, 'facecolor')) 				end;			end;		else            event2plot1 = find ( g.winrej(:,1) >= lowlim & g.winrej(:,1) <= highlim );            event2plot2 = find ( g.winrej(:,2) >= lowlim & g.winrej(:,2) <= highlim );            event2plot3 = find ( g.winrej(:,1) <  lowlim & g.winrej(:,2) >  highlim );            event2plot  = union(union(event2plot1, event2plot2), event2plot3);      			for tpmi = event2plot(:)'                h = patch([g.winrej(tpmi,1)-lowlim g.winrej(tpmi,2)-lowlim ...                           g.winrej(tpmi,2)-lowlim g.winrej(tpmi,1)-lowlim], ...                          [0 0 1 1], [g.winrej(tpmi,3) g.winrej(tpmi,4) g.winrej(tpmi,5)]);                  set(h, 'EdgeColor', get(h, 'facecolor')) 			end;		end;	end;    			% plot tags	% ---------    %if trialtag(1) ~= -1 & displaystatus % put tags at arbitrary places    % 	for tmptag = trialtag	%		if tmptag >= lowlim & tmptag <= highlim	%			plot([tmptag-lowlim tmptag-lowlim], [0 1], 'b--');   	%		end;	    %	end;    %end;    % draw events if any    % ------------------    if strcmpi(g.plotevent, 'on')                % find event to plot        % ------------------        event2plot    = find ( g.eventlatencies >=lowlim & g.eventlatencies <= highlim );        if ~isempty(g.eventlatencyend)                        event2plot2 = find ( g.eventlatencyend >= lowlim & g.eventlatencyend <= highlim );            event2plot3 = find ( g.eventlatencies  <  lowlim & g.eventlatencyend >  highlim );            event2plot  = union(union(event2plot, event2plot2), event2plot3);        end;        for index = 1:length(event2plot)            % draw latency line            % -----------------            tmplat = g.eventlatencies(event2plot(index))-lowlim-1;            tmph   = plot([ tmplat tmplat ], ylim, 'color', g.eventcolors{ event2plot(index) }, ...                          'linestyle', g.eventstyle { event2plot(index) }, ...                          'linewidth', g.eventwidths( event2plot(index) ) );                        % draw duration is not 0            % ----------------------            if ~isempty(g.eventlatencyend) ...                    & g.eventwidths( event2plot(index) ) ~= 2.5 % do not plot length of boundary events                tmplatend = g.eventlatencyend(event2plot(index))-lowlim-1;                if tmplatend ~= 0,                     tmplim = ylim;                    tmpcol = g.eventcolors{ event2plot(index) };                    h = patch([ tmplat tmplatend tmplatend tmplat ], ...                              [ tmplim(1) tmplim(1) tmplim(2) tmplim(2) ], ...                              tmpcol );  % this argument is color                    set(h, 'EdgeColor', 'none')                 end;            end;         end;    end;    if g.trialstag(1) ~= -1                % plot trial limits        % -----------------        tmptag = [lowlim:highlim];       	tmpind = find(mod(tmptag-1, g.trialstag) == 0);        for index = tmpind            plot([tmptag(index)-lowlim-1 tmptag(index)-lowlim-1], [0 1], 'b--');        end;        alltag = tmptag(tmpind);        % compute Xticks        % --------------        tagnum = (alltag-1)/g.trialstag+1;     	set(ax0,'XTickLabel', tagnum,'YTickLabel', [],...		'Xlim',[0 g.winlength*multiplier],...		'XTick',alltag-lowlim+g.trialstag/2, 'YTick',[], 'tag','backeeg');				axes(ax1);		tagpos  = [];		tagtext = [];		if ~isempty(alltag)			alltag = [alltag(1)-g.trialstag alltag alltag(end)+g.trialstag]; % add border trial limits		else			alltag = [ floor(lowlim/g.trialstag)*g.trialstag ceil(highlim/g.trialstag)*g.trialstag ]+1;		end;        		nbdiv = 20/g.winlength; % approximative number of divisions		divpossible = [ 100000./[1 2 4 5] 10000./[1 2 4 5] 1000./[1 2 4 5] 100./[1 2 4 5 10 20]]; % possible increments		[tmp indexdiv] = min(abs(nbdiv*divpossible-(g.limits(2)-g.limits(1)))); % closest possible increment		incrementpoint = divpossible(indexdiv)/1000*g.srate;		tagzerooffset  = -g.limits(1)/1000*g.srate; 		for i=1:length(alltag)-1			if ~isempty(tagpos) & tagpos(end)-alltag(i)<2*incrementpoint/3				tagpos  = tagpos(1:end-1);			end;			if ~isempty(g.freqlimits)				tagpos  = [ tagpos linspace(alltag(i),alltag(i+1)-1, nbdiv) ];			else				if tagzerooffset ~= 0					tmptagpos = [alltag(i)+tagzerooffset:-incrementpoint:alltag(i)];				else					tmptagpos = [];				end;				tagpos  = [ tagpos [tmptagpos(end:-1:2) alltag(i)+tagzerooffset:incrementpoint:(alltag(i+1)-1)]];			end;		end;        % find corresponding epochs        % -------------------------        tagtext = eeg_point2lat(tagpos, floor((tagpos)/g.trialstag)+1, g.srate, g.limits, 1E-3);     	set(ax1,'XTickLabel', tagtext,'XTick', tagpos-lowlim);			    else     	set(ax0,'XTickLabel', [],'YTickLabel', [],...		'Xlim',[0 g.winlength*multiplier],...		'XTick',[], 'YTick',[], 'tag','backeeg');		axes(ax1);    	set(ax1,'XTickLabel', num2str((g.time:DEFAULT_GRID_SPACING:g.time+g.winlength)'),...		'XTick',[1:multiplier*DEFAULT_GRID_SPACING:g.winlength*multiplier+1])    end;    		    % ordinates: even if all elec are plotted, some may be hidden    set(ax1, 'ylim',[g.elecoffset*g.spacing (g.elecoffset+g.dispchans+1)*g.spacing] );        axes(ax1)	  case 'draws'    % Redraw EEG and change scale    ax1 = findobj('tag','eegaxis','parent',gcf);         % axes handle    g = get(gcf,'UserData');      data = get(ax1, 'userdata');    ESpacing = findobj('tag','ESpacing','parent',gcf);   % ui handle    EPosition = findobj('tag','EPosition','parent',gcf); % ui handle    if g.trialstag(1) == -1        g.time    = str2num(get(EPosition,'string'));      else         g.time    = str2num(get(EPosition,'string'))-1;       end;            g.spacing = str2num(get(ESpacing,'string'));          orgspacing= g.spacing;    if p1 == 1      	g.spacing= g.spacing+ 0.1*orgspacing; % increase g.spacing(5%)	elseif p1 == 2		g.spacing= max(0,g.spacing-0.1*orgspacing); % decrease g.spacing(5%)    end    if round(g.spacing*100) == 0        maxindex = min(10000, g.frames);          g.spacing = 0.01*max(max(data(:,1:maxindex),[],2),[],1)-min(min(data(:,1:maxindex),[],2),[],1);  % Set g.spacingto max/min data    end;    set(ESpacing,'string',num2str(g.spacing,4))  % update edit box    set(gcf, 'userdata', g);	 eegplot('drawp', 0);    set(ax1,'YLim',[0 (g.chans+1)*g.spacing

⌨️ 快捷键说明

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