📄 topoplot.m
字号:
'EdgeColor','none','FaceColor',SHADING); end if strcmpi(MASKSURF, 'on') set(tmph, 'visible', 'off'); handle = tmph; end; [cls chs] = contour(Xi,Yi,Zi,CONTOURNUM,'k'); for h=chs, set(h,'color',CCOLOR); end % %%%%%%%%%%%%%%%%%%%%%%%% Else plot map only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % elseif strcmp(STYLE,'straight') | strcmp(STYLE,'map') % 'straight' was former arg if strcmp(SHADING,'interp') % 'interp' mode is shifted somehow... but how? tmph = surface(Xi*unsh,Yi*unsh,zeros(size(Zi)),Zi,'EdgeColor','none',... 'FaceColor',SHADING); else tmph = surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi)),Zi,'EdgeColor','none',... 'FaceColor',SHADING); end if strcmpi(MASKSURF, 'on') set(tmph, 'visible', 'off'); handle = tmph; end; % %%%%%%%%%%%%%%%%%% Else fill contours with uniform colors %%%%%%%%%%%%%%%%%% % elseif strcmp(STYLE,'fill') [cls chs] = contourf(Xi,Yi,Zi,CONTOURNUM,'k'); % for h=chs, set(h,'color',CCOLOR); end % <- 'not line objects.' Why does 'both' work above??? else error('Invalid style') end % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Set color axis %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % caxis([amin amax]) % set coloraxiselse % if STYLE 'blank'%%%%%%%%%%%%%%%%%%%%%%%% Draw blank head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if strcmpi(noplot, 'on') if strcmpi(VERBOSE,'on') fprintf('topoplot(): no plot requested.\n') end return; end cla hold on set(gca,'Xlim',[-rmax rmax]*AXHEADFAC,'Ylim',[-rmax rmax]*AXHEADFAC) % pos = get(gca,'position'); % fprintf('Current axes size %g,%g\n',pos(3),pos(4)); if strcmp(ELECTRODES,'labelpoint') | strcmp(ELECTRODES,'numpoint') text(-0.6,-0.6, ... [ int2str(length(Rd)) ' of ' int2str(length(tmpeloc)) ' electrode locations shown']); text(-0.6,-0.7, [ 'Click on electrodes to toggle name/number']); tl = title('Channel locations'); set(tl, 'fontweight', 'bold'); end;endif exist('handle') ~= 1 handle = gca;end;%%%%%%%%%%%%%%%%%%%% Plot filled ring to mask jagged grid boundary %%%%%%%%%%%%%%%%%%%%%%%%%%%%hwidth = HEADRINGWIDTH; % width of head ring hin = squeezefac*headrad*(1- hwidth/2); % inner head ring radiusif strcmp(SHADING,'interp') rwidth = BLANKINGRINGWIDTH*1.3; % width of blanking outer ringelse rwidth = BLANKINGRINGWIDTH; % width of blanking outer ringendrin = rmax*(1-rwidth/2); % inner ring radiusif hin>rin rin = hin; % dont blank inside the head ringendif strcmp(CONVHULL,'on') %%%%%%%%% mask outside the convex hull of the electrodes %%%%%%%%% cnv = convhull(allx,ally); cnvfac = round(CIRCGRID/length(cnv)); % spline interpolate the convex hull if cnvfac < 1, cnvfac=1; end; CIRCGRID = cnvfac*length(cnv); startangle = atan2(allx(cnv(1)),ally(cnv(1))); circ = linspace(0+startangle,2*pi+startangle,CIRCGRID); rx = sin(circ); ry = cos(circ); allx = allx(:)'; % make x (elec locations; + to nose) a row vector ally = ally(:)'; % make y (elec locations, + to r? ear) a row vector erad = sqrt(allx(cnv).^2+ally(cnv).^2); % convert to polar coordinates eang = atan2(allx(cnv),ally(cnv)); eang = unwrap(eang); eradi =spline(linspace(0,1,3*length(cnv)), [erad erad erad], ... linspace(0,1,3*length(cnv)*cnvfac)); eangi =spline(linspace(0,1,3*length(cnv)), [eang+2*pi eang eang-2*pi], ... linspace(0,1,3*length(cnv)*cnvfac)); xx = eradi.*sin(eangi); % convert back to rect coordinates yy = eradi.*cos(eangi); yy = yy(CIRCGRID+1:2*CIRCGRID); xx = xx(CIRCGRID+1:2*CIRCGRID); eangi = eangi(CIRCGRID+1:2*CIRCGRID); eradi = eradi(CIRCGRID+1:2*CIRCGRID); xx = xx*1.02; yy = yy*1.02; % extend spline outside electrode marks splrad = sqrt(xx.^2+yy.^2); % arc radius of spline points (yy,xx) oob = find(splrad >= rin); % enforce an upper bound on xx,yy xx(oob) = rin*xx(oob)./splrad(oob); % max radius = rin yy(oob) = rin*yy(oob)./splrad(oob); % max radius = rin splrad = sqrt(xx.^2+yy.^2); % arc radius of spline points (yy,xx) oob = find(splrad < hin); % don't let splrad be inside the head cartoon xx(oob) = hin*xx(oob)./splrad(oob); % min radius = hin yy(oob) = hin*yy(oob)./splrad(oob); % min radius = hin ringy = [[ry(:)' ry(1) ]*(rin+rwidth) yy yy(1)]; ringx = [[rx(:)' rx(1) ]*(rin+rwidth) xx xx(1)]; ringh2= patch(ringy,ringx,ones(size(ringy)),BACKCOLOR,'edgecolor','none'); hold on % plot(ry*rmax,rx*rmax,'b') % debugging lineelse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mask the jagged border around rmax %%%%%%%%%%%%%%%5%%%%%% circ = linspace(0,2*pi,CIRCGRID); rx = sin(circ); ry = cos(circ); ringx = [[rx(:)' rx(1) ]*(rin+rwidth) [rx(:)' rx(1)]*rin]; ringy = [[ry(:)' ry(1) ]*(rin+rwidth) [ry(:)' ry(1)]*rin]; if ~strcmpi(STYLE,'blank') ringh= patch(ringx,ringy,0.01*ones(size(ringx)),BACKCOLOR,'edgecolor','none'); hold on end % plot(ry*rmax,rx*rmax,'b') % debugging lineend %f1= fill(rin*[rx rX],rin*[ry rY],BACKCOLOR,'edgecolor',BACKCOLOR); hold on %f2= fill(rin*[rx rX*(1+rwidth)],rin*[ry rY*(1+rwidth)],BACKCOLOR,'edgecolor',BACKCOLOR);% Former line-style border smoothing - width did not scale with plot% brdr=plot(1.015*cos(circ).*rmax,1.015*sin(circ).*rmax,... % old line-based method% 'color',HEADCOLOR,'Linestyle','-','LineWidth',HLINEWIDTH); % plot skirt outline% set(brdr,'color',BACKCOLOR,'linewidth',HLINEWIDTH + 4); % hide the disk edge jaggies %%%%%%%%%%%%%%%%%%%%%%%%%% Plot cartoon head, ears, nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if headrad > 0 % if cartoon head to be plotted%%%%%%%%%%%%%%%%%%%% Plot head outline %%%%%%%%%%%%%%%%%%%%%%%%%%%%headx = [[rx(:)' rx(1) ]*(hin+hwidth) [rx(:)' rx(1)]*hin];heady = [[ry(:)' ry(1) ]*(hin+hwidth) [ry(:)' ry(1)]*hin];ringh= patch(headx,heady,ones(size(headx)),HEADCOLOR,'edgecolor',HEADCOLOR); hold on% rx = sin(circ); rX = rx(end:-1:1);% ry = cos(circ); rY = ry(end:-1:1);% for k=2:2:CIRCGRID% rx(k) = rx(k)*(1+hwidth);% ry(k) = ry(k)*(1+hwidth);% end% f3= fill(hin*[rx rX],hin*[ry rY],HEADCOLOR,'edgecolor',HEADCOLOR); hold on% f4= fill(hin*[rx rX*(1+hwidth)],hin*[ry rY*(1+hwidth)],HEADCOLOR,'edgecolor',HEADCOLOR);% Former line-style head% plot(cos(circ).*squeezefac*headrad,sin(circ).*squeezefac*headrad,...% 'color',HEADCOLOR,'Linestyle','-','LineWidth',HLINEWIDTH); % plot head outline%%%%%%%%%%%%%%%%%%%% Plot ears and nose %%%%%%%%%%%%%%%%%%%%%%%%%%%% base = rmax-.0046; basex = 0.18*rmax; % nose width tip = 1.15*rmax; tiphw = .04*rmax; % nose tip half width tipr = .01*rmax; % nose tip rounding q = .04; % ear lengthening EarX = [.497-.005 .510 .518 .5299 .5419 .54 .547 .532 .510 .489-.005]; % rmax = 0.5 EarY = [q+.0555 q+.0775 q+.0783 q+.0746 q+.0555 -.0055 -.0932 -.1313 -.1384 -.1199]; sf = headrad/plotrad; % squeeze the model ears and nose % by this factor plot3([basex;tiphw;0;-tiphw;-basex]*sf,[base;tip-tipr;tip;tip-tipr;base]*sf,... 2*ones(size([basex;tiphw;0;-tiphw;-basex])),... 'Color',HEADCOLOR,'LineWidth',HLINEWIDTH); % plot nose plot3(EarX*sf,EarY*sf,2*ones(size(EarX)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH) % plot left ear plot3(-EarX*sf,EarY*sf,2*ones(size(EarY)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH) % plot right earend%% %%%%%%%%%%%%%%%%%%% Show electrode information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotax = gca; axis square % make plotax square axis off pos = get(gca,'position'); xlm = get(gca,'xlim'); ylm = get(gca,'ylim'); % textax = axes('position',pos,'xlim',xlm,'ylim',ylm); % make new axes so clicking numbers <-> labels % will work inside head cartoon patch % axes(textax); axis square % make textax square pos = get(gca,'position'); set(plotax,'position',pos); xlm = get(gca,'xlim'); set(plotax,'xlim',xlm); ylm = get(gca,'ylim'); set(plotax,'ylim',ylm); % copy position and axis limits again%get(textax,'pos') % test if equal!%get(plotax,'pos')%get(textax,'xlim')%get(plotax,'xlim')%get(textax,'ylim')%get(plotax,'ylim') if isempty(EMARKERSIZE) EMARKERSIZE = 10; if length(y)>=32 EMARKERSIZE = 8; elseif length(y)>=48 EMARKERSIZE = 6; elseif length(y)>=64 EMARKERSIZE = 5; elseif length(y)>=80 EMARKERSIZE = 4; elseif length(y)>=100 EMARKERSIZE = 3; elseif length(y)>=128 EMARKERSIZE = 2; elseif length(y)>=160 EMARKERSIZE = 1; end end%%%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations only %%%%%%%%%%%%%%%%%%%%%%%%%%%ELECTRODE_HEIGHT = 2.1; % z value for plotting electrode information (above the surf)if strcmp(ELECTRODES,'on') % plot electrodes as spots hp2 = plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE);%%%%%%%%%%%%%%%%%%%%%%%%% Print electrode labels only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(ELECTRODES,'labels') % print electrode names (labels) for i = 1:size(labels,1) text(y(i),x(i),ELECTRODE_HEIGHT,labels(i,:),'HorizontalAlignment','center',... 'VerticalAlignment','middle','Color',ECOLOR,... 'FontSize',EFSIZE) end%%%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations plus labels %%%%%%%%%%%%%%%%%%%%elseif strcmp(ELECTRODES,'labelpoint') hp2 = plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE); for i = 1:size(labels,1) hh(i) = text(y(i)+0.01,x(i),ELECTRODE_HEIGHT,labels(i,:),'HorizontalAlignment','left',... 'VerticalAlignment','middle','Color', ECOLOR,'userdata', num2str(pltchans(i)), ... 'FontSize',EFSIZE, 'buttondownfcn', ... ['tmpstr = get(gco, ''userdata'');'... 'set(gco, ''userdata'', get(gco, ''string''));' ... 'set(gco, ''string'', tmpstr); clear tmpstr;'] ); end%%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations plus numbers %%%%%%%%%%%%%%%%%%%%elseif strcmp(ELECTRODES,'numpoint') hp2 = plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE); for i = 1:size(labels,1) hh(i) = text(y(i)+0.01,x(i),ELECTRODE_HEIGHT,num2str(pltchans(i)),'HorizontalAlignment','left',... 'VerticalAlignment','middle','Color', ECOLOR,'userdata', labels(i,:) , ... 'FontSize',EFSIZE, 'buttondownfcn', ... ['tmpstr = get(gco, ''userdata'');'... 'set(gco, ''userdata'', get(gco, ''string''));' ... 'set(gco, ''string'', tmpstr); clear tmpstr;'] ); end%%%%%%%%%%%%%%%%%%%%%%% Print electrode numbers only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(ELECTRODES,'numbers') for i = 1:size(labels,1) text(y(i),x(i),ELECTRODE_HEIGHT,int2str(pltchans(i)),'HorizontalAlignment','center',... 'VerticalAlignment','middle','Color',ECOLOR,... 'FontSize',EFSIZE) endend%%%%%%%%%%%%%%%%%%%%%%% Mark specified electrode locations %%%%%%%%%%%%%%%%%%%%%%%%if strcmpi(STYLE,'blank') % if mark-selected-channel-locations mode if length(Values) < length(pltchans) % mark selected electrodes for kk = 1:length(Values) hp2 = plot3(y(Values(kk)),x(Values(kk)),ELECTRODE_HEIGHT,'.','Color', EMARKERCOLOR1CHAN, ... 'markersize', EMARKERSIZE1CHAN); hold on end end;end%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plot dipole(s) on the scalp map %%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~isempty(DIPOLE) hold on; tmp = DIPOLE; if isstruct(DIPOLE) if ~isfield(tmp,'posxyz') error('dipole structure is not an EEG.dipfit.model') end DIPOLE = []; % Note: invert x and y from dipplot usage DIPOLE(:,1) = -tmp.posxyz(:,2)/DIPSPHERE; % -y -> x DIPOLE(:,2) = tmp.posxyz(:,1)/DIPSPHERE; % x -> y DIPOLE(:,3) = -tmp.momxyz(:,2); DIPOLE(:,4) = tmp.momxyz(:,1); else DIPOLE(:,1) = -tmp(:,2); % same for vector input DIPOLE(:,2) = tmp(:,1); DIPOLE(:,3) = -tmp(:,4); DIPOLE(:,4) = tmp(:,3); end; for index = 1:size(DIPOLE,1) if ~any(DIPOLE(index,:)) DIPOLE(index,:) = []; end end; DIPOLE(:,1:4) = DIPOLE(:,1:4)*rmax*(rmax/plotrad); % scale radius from 1 -> rmax (0.5) DIPOLE(:,3:end) = (DIPOLE(:,3:end))*rmax/100000*(rmax/plotrad); if strcmpi(DIPNORM, 'on') for index = 1:size(DIPOLE,1) DIPOLE(index,3:4) = DIPOLE(index,3:4)/norm(DIPOLE(index,3:end))*0.2; end; end; DIPOLE(:, 3:4) = DIPORIENT*DIPOLE(:, 3:4)*DIPLEN; PLOT_DIPOLE=1; if sum(DIPOLE(1,3:4).^2) <= 0.00001 if strcmpi(VERBOSE,'on') fprintf('Note: dipole is length 0 - not plotted\n') end PLOT_DIPOLE = 0; end if 0 % sum(DIPOLE(1,1:2).^2) > plotrad if strcmpi(VERBOSE,'on') fprintf('Note: dipole is outside plotting area - not plotted\n') end PLOT_DIPOLE = 0; end if PLOT_DIPOLE for index = 1:size(DIPOLE,1) hh = plot( DIPOLE(index, 1), DIPOLE(index, 2), '.'); set(hh, 'color', DIPCOLOR, 'markersize', DIPSCALE*30); hh = line( [DIPOLE(index, 1) DIPOLE(index, 1)+DIPOLE(index, 3)]', ... [DIPOLE(index, 2) DIPOLE(index, 2)+DIPOLE(index, 4)]'); set(hh, 'color', DIPCOLOR, 'linewidth', DIPSCALE*30/7); end; end;end;%%%%%%%%%%%%%% Set EEGLAB background color to match head border %%%%%%%%%%%%%%%%%%%%%%%%%try, icadefs; set(gcf, 'color', BACKCOLOR); catch, end; hold offaxis offreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -