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

📄 topoplot.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 4 页
字号:
	  if isstr(headrad) & ( strcmpi(headrad,'off') | strcmpi(headrad,'none') )	    headrad = 0;       % undocumented 'no head' alternatives	  end	  if isempty(headrad) % [] -> none also	    headrad = 0;	  end	  if ~isstr(headrad) 	    if ~(headrad==0) & (headrad < MINPLOTRAD | headrad>1)	      error('bad value for headrad');	    end	  elseif  ~strcmpi(headrad,'rim')	    error('bad value for headrad');	  end	 case {'headcolor','hcolor'}	  HEADCOLOR = Value;	 case {'contourcolor','ccolor'}	  CCOLOR = Value;	 case {'electcolor','ecolor'}	  ECOLOR = Value;	 case {'emarkersize','emsize'}	  EMARKERSIZE = Value;	 case 'emarkersize1chan'	  EMARKERSIZE1CHAN= Value;	 case {'efontsize','efsize'}	  EFSIZE = Value;	 case 'shading'	  SHADING = lower(Value);	  if ~any(strcmp(SHADING,{'flat','interp'}))	     error('Invalid shading parameter')	  end         case 'noplot'          noplot = Value;          if ~isstr(noplot)            if length(noplot) ~= 2              error('''noplot'' location should be [radius, angle]')            else              chanrad = noplot(1);              chantheta = noplot(2);              noplot = 'on';            end          end         case 'gridscale'          GRID_SCALE = Value;          if isstr(GRID_SCALE) | GRID_SCALE ~= round(GRID_SCALE) | GRID_SCALE < 32               error('''gridscale'' value must be integer > 32.\n');          end	 otherwise	  error(['Unknown input parameter ''' Param ''' ???'])    end  endendif isempty(ELECTRODES)                     % if electrode labeling not specified  if length(Values) > MAXDEFAULTSHOWLOCS   % if more channels than default max    ELECTRODES = 'off';                    % don't show electrodes  else                                     % else if fewer chans    ELECTRODES = 'on';                     % do  endendif isempty(Values)   STYLE = 'blank';end[r,c] = size(Values);if r>1 & c>1,  error('input data must be a single vector');elseif r==1 & c==1  STYLE = 'blank'; % plot channels only, marking the indicated channel numberendif ~isempty(intrad) & ~isempty(plotrad) & intrad < plotrad   error('intrad must be >= plotrad');end%%%%%%%%%%%%%%%%%%%%% Read the channel location information %%%%%%%%%%%%%%%%%%%%%%%%% if isstr(loc_file)	[tmpeloc labels Th Rd indices] = readlocs(loc_file,'filetype','loc');else % a locs struct	[tmpeloc labels Th Rd indices] = readlocs(loc_file);        % Note: Th and Rd correspond to indices channels-with-coordinates onlyendif length(tmpeloc) == length(Values) + 1 % remove last channel if necessary                                          % (common reference channel)    tmpeloc(end) = [];    labels(end) = [];    Th(end) = [];    Rd(end) = [];    ni = length(indices);    fixit = find(indices==ni);    if ~isempty(ni)        indices(fixit) = [];    endend;Th = pi/180*Th;                              % convert degrees to radiansif length(Values) > 1   if max(indices)>length(Values)      if strcmpi(VERBOSE, 'on')        fprintf('topoplot(): max chan number (%d) in locs > channels in data (%d).\n',...                                   max(indices),length(Values));        fprintf('            Marking the locations of the %d indicated channels.\n', ...                                    length(Values));      end      STYLE = 'blank';   else      Values     = Values(indices);   endend;labels = labels(indices); % remove labels for electrodes without locationslabels = strvcat(labels); % make a label string matrix%%%%%%%%%%%%%%%%%%% Read plotting radius from chanlocs  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if isempty(plotrad) & isfield(tmpeloc, 'plotrad'),     plotrad = tmpeloc(1).plotrad;     if isstr(plotrad)                        % plotrad shouldn't be a string        plotrad = str2num(plotrad)           % just checking    end    if plotrad < MINPLOTRAD | plotrad > 1.0       fprintf('Bad value (%g) for plotrad.\n',plotrad);       error(' ');    end    if strcmpi(VERBOSE,'on') & ~isempty(plotrad)       fprintf('Plotting radius plotrad (%g) set from EEG.chanlocs.\n',plotrad);    endend;if isempty(plotrad)   plotrad = min(1.0,max(Rd)*1.02);            % default: just outside the outermost electrode location  plotrad = max(plotrad,0.5);                 % default: plot out to the 0.5 head boundaryend                                           % don't plot channels with Rd > 1 (below head)if isempty(intrad)   intrad = min(1.0,max(Rd)*1.02);             % default: just outside the outermost electrode locationend                                           % don't interpolate channels with Rd > 1 (below head)if isstr(plotrad) | plotrad < MINPLOTRAD | plotrad > 1.0   error('plotrad must be between 0.15 and 1.0');end% plotrad now set%%%%%%%%%%%%%%%%%%%%%%%% Set radius of head cartoon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if isempty(headrad)  % never set -> defaults  if plotrad >= rmax     headrad = rmax;  % (anatomically correct)  else % if plotrad < rmax     headrad = 0;    % don't plot head     if strcmpi(VERBOSE, 'on')       fprintf('topoplot(): not plotting cartoon head since plotrad (%5.4g) < 0.5\n',...                                                                    plotrad);     end  endelseif strcmpi(headrad,'rim') % force plotting at rim of map  headrad = plotrad;end% headrad now set%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Shrink mode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~isempty(shrinkfactor) | isfield(tmpeloc, 'shrink'),         if isempty(shrinkfactor) & isfield(tmpeloc, 'shrink'),         shrinkfactor = tmpeloc(1).shrink;        if strcmpi(VERBOSE,'on')            if isstr(shrinkfactor)                fprintf('Automatically shrinking coordinates\n');            else                                fprintf('Automatically shrinking coordinates by 3.2f\n', shrinkfactor);            end;        end    end;        if isstr(shrinkfactor)        if strcmpi(shrinkfactor, 'on') | strcmpi(shrinkfactor, 'force') | strcmpi(shrinkfactor, 'auto')              if strcmpi(VERBOSE,'on')                fprintf('     Shrink flag -> plotting cartoon head at plotrad\n');            end            headrad = plotrad; % plot head around outer electrodes, no matter if 0.5 or not        end    else % apply shrinkfactor        plotrad = rmax/(1-shrinkfactor);        headrad = plotrad;  % make deprecated 'shrink' mode plot         if strcmpi(VERBOSE,'on')            fprintf('    %g%% shrink  applied.');            if abs(headrad-rmax) > 1e-2                fprintf(' Cartoon head is not anatomically correct.\n');            else                fprintf('\n');            end        end    endend; % if shrink      %%%%%%%%%%%%%%%%%% Issue warning if headrad ~= rmax  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if headrad ~= 0.5 & strcmpi(VERBOSE, 'on')   fprintf('     NB: Plotting map using ''plotrad'' %-4.3g,',plotrad);   fprintf(    ' ''headrad'' %-4.3g\n',headrad);   fprintf('Warning: The plotting radius of the cartoon head is NOT anatomically correct (0.5).\n')end%%%%%%%%%%%%%%%%%%%%%% Find plotting channels  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% pltchans = find(Rd <= plotrad); % plot channels inside plotting circle[x,y] = pol2cart(Th,Rd);  % transform from polar to cartesian coordinatesif strcmpi(INTSQUARE,'on') &  ~strcmpi(STYLE,'blank') % interpolate channels in the radius intrad square  intchans = find(x <= intrad & y <= intrad); % interpolate and plot channels inside interpolation squareelse  intchans = find(Rd <= intrad); % interpolate channels in the radius intrad circle onlyendif length(pltchans) < length(Rd) & strcmpi(VERBOSE, 'on')        fprintf('Interpolating %d and plotting %d of the %d scalp electrodes.\n', ...                   length(intchans),length(pltchans),length(Rd));    end;	%%%%%%%%%%%%%%%%%%%%%% Eliminate channels not plotted  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if ~isempty(Values)	if length(Values) == length(Th)  % if as many map Values as channel locs		intValues = Values(intchans);		Values = Values(pltchans);	else if strcmp(STYLE,'blank')    % else if Values holds numbers of channels to mark            tmpValues=[];            cc=1;            for kk=1:length(Values)                tmpind = find(pltchans == Values(kk));                if ~isempty(tmpind)                    tmpValues(cc) = tmpind;                    cc=cc+1;                end;            end            Values=tmpValues;     % eliminate the channel indices outside plotting area		end;	end;	end;   % now channel parameters and values all refer to plotting channels onlyintTh = Th(intchans);           % eliminate channels outside the interpolation areaintRd = Rd(intchans);intx  = x(intchans);inty  = y(intchans);Th    = Th(pltchans);              % eliminate channels outside the plotting areaRd    = Rd(pltchans);allx = x;ally = y;x     = x(pltchans);y     = y(pltchans);labels= labels(pltchans,:);%%%%%%%%%%%%%%%% Squeeze channel locations to <= rmax %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% squeezefac = rmax/plotrad;intRd = intRd*squeezefac; % squeeze electrode arc_lengths towards the vertexRd = Rd*squeezefac;       % squeeze electrode arc_lengths towards the vertex                          % to plot all inside the head cartoonintx = intx*squeezefac;   inty = inty*squeezefac;  x    = x*squeezefac;    y    = y*squeezefac;   allx    = allx*squeezefac;    ally    = ally*squeezefac;   % Note: Now outermost channel will be plotted just inside rmax%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Make the plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if ~strcmpi(STYLE,'blank') % if draw interpolated scalp map  %  %%%%%%%%%%%%%%%% Find limits for interpolation %%%%%%%%%%%%%%%%%%%%%%%%%%%%  %  if strcmpi(INTERPLIMITS,'head')    xmin = min(-rmax,min(intx)); xmax = max(rmax,max(intx));    ymin = min(-rmax,min(inty)); ymax = max(rmax,max(inty));  else % INTERPLIMITS = rectangle containing electrodes   ??? SAME ???    xmin = max(-rmax,min(intx)); xmax = min(rmax,max(intx));    ymin = max(-rmax,min(inty)); ymax = min(rmax,max(inty));  end  %  %%%%%%%%%%%%%%%%%%%%%%% Interpolate scalp map data %%%%%%%%%%%%%%%%%%%%%%%%  %  xi = linspace(xmin,xmax,GRID_SCALE);   % x-axis description (row vector)  yi = linspace(ymin,ymax,GRID_SCALE);   % y-axis description (row vector)  [Xi,Yi,Zi] = griddata(inty,intx,intValues,yi',xi,'invdist'); % interpolate data  %  %%%%%%%%%%%%%%%%%%%%%%% Mask out data outside the head %%%%%%%%%%%%%%%%%%%%%  %  mask = (sqrt(Xi.^2 + Yi.^2) <= rmax); % mask outside the plotting circle  ii = find(mask == 0);  Zi(ii) = NaN;                         % mask non-plotting voxels with NaNs  %  %%%%%%%%%% Return interpolated value at designated scalp location %%%%%%%%%%  %  if exist('chanrad')   % optional first argument to 'noplot'       chantheta = (chantheta/360)*2*pi;      chancoords = round(ceil(GRID_SCALE/2)+GRID_SCALE/2*2*chanrad*[cos(-chantheta),...                                                      -sin(-chantheta)]);      if chancoords(1)<1 ...         | chancoords(1) > GRID_SCALE ...            | chancoords(2)<1 ...               | chancoords(2)>GRID_SCALE          error('designated ''noplot'' channel out of bounds')      else        chanval = Zi(chancoords(1),chancoords(2));        Zi = chanval;  % return interpolated value instead of Zi      end  end  %  %%%%%%%%%%%%%%%%%%%%%%%%%% Return interpolated image only  %%%%%%%%%%%%%%%%%  %   if strcmpi(noplot, 'on')     if strcmpi(VERBOSE,'on')       fprintf('topoplot(): no plot requested.\n')    end    return;   end  %  %%%%%%%%%%%%%%%%%%%%%%% Calculate colormap limits %%%%%%%%%%%%%%%%%%%%%%%%%%  %  m = size(colormap,1);  if isstr(MAPLIMITS)    if strcmp(MAPLIMITS,'absmax')      amin = -max(max(abs(Zi)));      amax = max(max(abs(Zi)));    elseif strcmp(MAPLIMITS,'maxmin') | strcmp(MAPLIMITS,'minmax')      amin = min(min(Zi));      amax = max(max(Zi));    else      error('unknown ''maplimits'' value.');    end  else    amin = MAPLIMITS(1);    amax = MAPLIMITS(2);  end  delta = xi(2)-xi(1); % length of grid entry  %  %%%%%%%%%%%%%%%%%%%%%%%%%% Scale the axes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %  cla  % clear current axis  hold on  h = gca; % uses current axes                          % instead of default larger AXHEADFAC   if squeezefac<0.92 & plotrad-headrad > 0.05  % (size of head in axes)    AXHEADFAC = 1.05;     % do not leave room for external ears if head cartoon                          % shrunk enough by the 'skirt' option  end  set(gca,'Xlim',[-rmax rmax]*AXHEADFAC,'Ylim',[-rmax rmax]*AXHEADFAC);                          % specify size of head axes in gca  unsh = (GRID_SCALE+1)/GRID_SCALE; % un-shrink the effects of 'interp' SHADING  %  %%%%%%%%%%%%%%%%%%%%%%%% Plot map contours only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %  if strcmp(STYLE,'contour')                     % plot surface contours only    [cls chs] = contour(Xi,Yi,Zi,CONTOURNUM,'k');     % for h=chs, set(h,'color',CCOLOR); end  %  %%%%%%%%%%%%%%%%%%%%%%%% Else plot map and contours %%%%%%%%%%%%%%%%%%%%%%%%%  %  elseif strcmp(STYLE,'both')  % plot interpolated surface and surface contours    if strcmp(SHADING,'interp')       tmph = surface(Xi*unsh,Yi*unsh,zeros(size(Zi)),Zi,...               'EdgeColor','none','FaceColor',SHADING);                        else % SHADING == 'flat'       tmph = surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi)),Zi,...

⌨️ 快捷键说明

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