envtopo.m
来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 1,112 行 · 第 1/3 页
M
1,112 行
set(newaxes,'Color',BACKCOLOR); % set the background colordelete(newaxes) %XXX% site the plot at bottom of the current axes%axe = axes('Units','Normalized','Position',...axe = axes('Position',... [pos(1) pos(2) pos(3) 0.6*pos(4)],... 'FontSize',16,'FontWeight','Bold');g.limits = get(axe,'Ylim');set(axe,'GridLineStyle',':')set(axe,'Xgrid','off')set(axe,'Ygrid','on')axes(axe)set(axe,'Color',axcolor);% fprintf('Using limits [%g,%g,%g,%g]\n',xmin,xmax,ymin,ymax);%%%%%%%%%%%%%%%%%% plot the envelope of the summed selected components %%%%%%%%%%%%%%%%%%if BOLD_COLORS==1 mapcolors = 1:ntopos+1;else mapcolors = [1 maporder+1];endif strcmpi(g.sumenv,'on') | strcmpi(g.sumenv,'fill') FILLCOLOR = [.66 .76 1]; sumenv = envelope(sumproj(g.plotchans,:), g.envmode); if strcmpi(g.sumenv,'fill') % % plot the summed projection filled % mins = matsel(sumenv,frames,0,2,0); p=fill([times times(frames:-1:1)],... [matsel(sumenv,frames,0,1,0) mins(frames:-1:1)],FILLCOLOR); set(p,'EdgeColor',FILLCOLOR); hold on % % Overplot the data envelope again so it is not covered by the fill()'d component % p=plot(times,matsel(envdata,frames,0,1,1),colors(mapcolors(1),1));% plot the max set(p,'LineWidth',2); % component order (if BOLD_COLORS==0) p=plot(times,matsel(envdata,frames,0,2,1),colors(mapcolors(1),1));% plot the min set(p,'LineWidth',2); % component order (if BOLD_COLORS==0) else p=plot(times,matsel(sumenv,frames,0,2,0));% plot the min hold on set(p,'color',FILLCOLOR); set(p,'linewidth',2); p=plot(times,matsel(sumenv,frames,0,1,0));% plot the max set(p,'linewidth',2); set(p,'color',FILLCOLOR); endendif strcmpi(g.pvaf,'on') t = text(xmin+0.1*(xmax-xmin), ... ymin+0.1*(ymax-ymin), ... ['pvaf ' num2str(sumpvaf,'%4.2f') '%']); set(t,'fontsize',12,'fontweight','bold')end%% %%%%%%%%%%%%%%%%%%%%%%%% plot the computed component envelopes %%%%%%%%%%%%%%%%%%% envx = [1;compx+1]; for c = 1:ntopos+1 p=plot(times,matsel(envdata,frames,0,1,envx(c)),colors(mapcolors(c),1));% plot the max set(gca,'FontSize',12,'FontWeight','Bold') if c==1 % Note: use colors in original set(p,'LineWidth',2); % component order (if BOLD_COLORS==0) else set(p,'LineWidth',1); end if all_bold > 0 set(p,'LineStyle','-','LineWidth',3); elseif mapcolors(c)>15 % thin/dot 16th-> comp. envs. set(p,'LineStyle',':','LineWidth',1); elseif mapcolors(c)>10 % set(p,'LineStyle',':','LineWidth',2); elseif mapcolors(c)>6 % dot 6th-> comp. envs. set(p,'LineStyle',':','LineWidth',3); elseif mapcolors(c)>1 set(p,'LineStyle',colors(mapcolors(c),2),'LineWidth',1); if colors(mapcolors(c),2) == ':' set(l1,'LineWidth',2); % embolden dotted env lines end end hold on p=plot(times,matsel(envdata,frames,0,2,envx(c)),colors(mapcolors(c),1));% plot the min if c==1 set(p,'LineWidth',2); else set(p,'LineWidth',1); end if all_bold > 0 set(p,'LineStyle','-','LineWidth',3); elseif mapcolors(c)>15 % thin/dot 11th-> comp. envs. set(p,'LineStyle',':','LineWidth',1); elseif mapcolors(c)>10 set(p,'LineStyle',':','LineWidth',2); elseif mapcolors(c)>6 % dot 6th-> comp. envs. set(p,'LineStyle',':','LineWidth',3); elseif mapcolors(c)>1 set(p,'LineStyle',colors(mapcolors(c),2),'LineWidth',1); if colors(mapcolors(c),2) == ':' set(l1,'LineWidth',2); % embolden dotted env lines end end if c==1 & ~isempty(g.vert) for v=g.vert vl=plot([v v], [ymin ymax],'k--'); % plot specified vertical lines set(vl,'linewidth',2.5); % if any end end if g.limits(1) <= 0 & g.limits(2) >= 0 vl=plot([0 0], [ymin ymax],'k'); % plot specified vertical lines set(vl,'linewidth',2); % if any end % % plot the n-th component filled % if g.fillcomp(1)>0 & find(g.fillcomp==c-1) fprintf('filling the envelope of component %d\n',c-1); mins = matsel(envdata,frames,0,2,envx(c)); p=fill([times times(frames:-1:1)],... [matsel(envdata,frames,0,1,envx(c)) mins(frames:-1:1)],... colors(mapcolors(c),1)); % % Overplot the data envlope again so it is not covered by the fill()'d component % p=plot(times,matsel(envdata,frames,0,1,envx(1)),colors(mapcolors(1),1));% plot the max set(p,'LineWidth',2); % component order (if BOLD_COLORS==0) p=plot(times,matsel(envdata,frames,0,2,envx(1)),colors(mapcolors(1),1));% plot the min set(p,'LineWidth',2); % component order (if BOLD_COLORS==0) end axis([xmin xmax ymin ymax]); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%set(axe,'Color',axcolor);l= xlabel('Time (ms)');% l= xlabel('Time (ms)');set(l,'FontSize',14,'FontWeight','Bold');if strcmpi(g.envmode, 'avg') l=ylabel('Potential (uV)');else l=ylabel('RMS of uV');end; % l=ylabel('Potential (uV)');set(l,'FontSize',14,'FontWeight','Bold');%%%%%%%%%%%%%%%%%%%%%%% Draw oblique/vertical lines %%%%%%%%%%%%%%%%%%%%%% axall = axes('Units','Normalized','Position',pos,...axall = axes('Position',pos,... 'Visible','Off','Fontsize',16); % whole-figure invisible axesaxes(axall)set(axall,'Color',axcolor);axis([0 1 0 1])width = xmax-xmin;height = ymax-ymin;if strcmpi(g.dispmaps, 'on') for t=1:ntopos % draw oblique lines from max env vals (or plot top) % to map bases, in left to right order if BOLD_COLORS==1 linestyles = 1:ntopos; else linestyles = maporder; end axes(axall) axis([0 1 0 1]); set(axall,'Visible','off'); maxenv = matsel(envdata,frames,plotframes(t),1,compx(t)+1); % max env val data_y = 0.6*(g.voffsets(t)+maxenv-ymin)/height; if (data_y > pos(2)+0.6*pos(4)) data_y = pos(2)+0.6*pos(4); end l1 = plot([(plottimes(t)-xmin)/width ... topoleft+1/pos(3)*(t-1)*6*topowidth/5+topowidth*0.6],... [data_y 0.68], ... colors(linestyles(t)+1)); % 0.68 is bottom of topo maps if all_bold > 0 set(l1,'LineStyle','-','LineWidth',3); elseif linestyles(t)>15 % thin/dot 11th-> comp. envs. set(l1,'LineStyle',':','LineWidth',1); elseif linestyles(t)>10 set(l1,'LineStyle',':','LineWidth',2); elseif linestyles(t)>5 % dot 6th-> comp. envs. set(l1,'LineStyle',':','LineWidth',3); elseif linestyles(t)>1 set(l1,'LineStyle',colors(linestyles(t)+1,2),'LineWidth',1); if colors(linestyles(t)+1,2) == ':' set(l1,'LineStyle',colors(linestyles(t)+1,2),'LineWidth',2); end end hold on if g.voffsets(t) > 0 % if needed add vertical lines l2 = plot([(plottimes(t)-xmin)/width ... (plottimes(t)-xmin)/width],... [0.6*(maxenv-ymin)/height ... 0.6*(g.voffsets(t)+maxenv-ymin)/height],... colors(linestyles(t)+1)); if all_bold > 0 set(l2,'LineStyle','-','LineWidth',3); elseif linestyles(t)>15 % thin/dot 11th-> comp. envs. set(l2,'LineStyle',':','LineWidth',1); elseif linestyles(t)>10 set(l2,'LineStyle',':','LineWidth',2); elseif linestyles(t)>5 % dot 6th-> comp. envs. set(l2,'LineStyle',':','LineWidth',3); else set(l1,'LineStyle',colors(linestyles(t)+1,2),'LineWidth',1); if colors(linestyles(t)+1,2) == ':' set(l1,'LineWidth',2); end end end set(gca,'Visible','off'); axis([0 1 0 1]); endend;%%%%%%%%%%%%%%%%%%%%%%%%%% Plot the topoplots %%%%%%%%%%%%%%%%%%%%%%%%%%%if strcmpi(g.dispmaps, 'on') % common scale for colors % ----------------------- if strcmpi(g.actscale, 'on') maxvolt = 0; for n=1:ntopos maxvolt = max(max(abs(maxproj(:,n))), maxvolt); end; end; [tmp tmpsort] = sort(maporder); [tmp tmpsort] = sort(tmpsort); if isstr(g.chanlocs) if exist(g.chanlocs) ~= 2 % if no such file fprintf('envtopo(): named channel location file not found.\n',chans); return end eloc = readlocs(g.chanlocs); if length(eloc) ~= chans fprintf('envtopo() error: %d channels not read from the named channel location file.\n',chans); return end end for t=1:ntopos % left to right order % axt = axes('Units','Normalized','Position',... axt = axes('Units','Normalized','Position',... [pos(3)*topoleft+pos(1)+(t-1)*head_sep*topowidth pos(2)+0.66*pos(4) ... topowidth topowidth*head_sep]); axes(axt) % topoplot axes cla if ~isempty(g.chanlocs) if ~isempty(varargin) topoplot(maxproj(:,t),g.chanlocs, varargin{:}); else topoplot(maxproj(:,t),g.chanlocs,'style','both','emarkersize',3); end axis square if strcmpi(g.pvaf, 'on') set(gca, 'userdata', ['text(-0.6, -0.6, ''pvaf: ' sprintf('%6.2f', pvaf(tmpsort(t))) ''');'] ); else set(gca, 'userdata', ['text(-0.6, -0.6, ''rv: ' sprintf('%6.2f', pvaf(tmpsort(t))) ''');'] ); end; else axis off; end; % scale colors % ------------ if strcmpi(g.actscale, 'on') caxis([-maxvolt maxvolt]); end; if t==1 chid = fopen('envtopo.labels','r'); if chid <3, numlabels = 1; else fprintf('Will label scalp maps with labels from file %s\n','envtopo.labels'); compnames = fscanf(chid,'%s',[4 MAXPLOTDATACHANS]); compnames = compnames'; [r c] = size(compnames); for i=1:r for j=1:c if compnames(i,j)=='.', compnames(i,j)=' '; end; end; end; numlabels=0; end end if numlabels == 1 complabel = int2str(maporder(t)); % label comp. numbers else complabel = compnames(t,:); % use labels in file end text(0.00,0.60,complabel,'FontSize',14,... 'FontWeight','Bold','HorizontalAlignment','Center'); % axt = axes('Units','Normalized','Position',[0 0 1 1],... axt = axes('Position',[0 0 1 1],... 'Visible','Off','Fontsize',16); set(axt,'Color',axcolor); % topoplot axes drawnow end % %%%%%%%%%%%%%%%%%%%%%%%%%%% Plot a colorbar %%%%%%%%%%%%%%%%%%%%%%%%%% % % axt = axes('Units','Normalized','Position',[.88 .58 .03 .10]); axt = axes('Position',[pos(1)+pos(3)*1.02 pos(2)+0.6*pos(4) pos(3)*.02 pos(4)*0.09]); if strcmpi(g.actscale, 'on') h=cbar(axt, [1:64],[-maxvolt maxvolt],3); else h=cbar(axt); % colorbar axes set(h,'Ytick',[]); axes(axall) set(axall,'Color',axcolor); tmp = text(0.50,1.05,g.title,'FontSize',16,'HorizontalAlignment','Center','FontWeight','Bold'); set(tmp, 'interpreter', 'none'); text(0.98,0.68,'+','FontSize',16,'HorizontalAlignment','Center'); text(0.98,0.62,'-','FontSize',16,'HorizontalAlignment','Center'); end; axes(axall) set(axall,'layer','top'); % bring component lines to top end;axcopy(gcf, 'if ~isempty(get(gca, ''''userdata'''')), eval(get(gca, ''''userdata'''')); end;');return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function envdata = envelope(data, envmode) % also in release as env() if nargin < 2 envmode = 'avg'; end; if strcmpi(envmode, 'rms'); warning off; negflag = (data < 0); dataneg = negflag.* data; dataneg = -sqrt(sum(dataneg.*dataneg,1) ./ sum(negflag,1)); posflag = (data > 0); datapos = posflag.* data; datapos = sqrt(sum(datapos.*datapos,1) ./ sum(posflag,1)); envdata = [datapos;dataneg]; warning on; else if size(data,1)>1 maxdata = max(data); % max at each time point mindata = min(data); % min at each time point envdata = [maxdata;mindata]; else maxdata = max([data;data]); % max at each time point mindata = min([data;data]); % min at each time point envdata = [maxdata;mindata]; end end; return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?