plottopo.m

来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 897 行 · 第 1/3 页

M
897
字号
  if g.frames <=0,    g.frames = framestotal;    % default    datasets=1;  elseif g.frames==1,    fprintf('plottopo: cannot plot less than 2 frames per trace.\n');    return    datasets=1;  else    datasets = fix(framestotal/g.frames);        % number of traces to overplot  end;  if max(channelnos) > chans    fprintf('plottopo(): max channel index > %d channels in data.\n',...                       chans);    return  end  if min(channelnos) < 1    fprintf('plottopo(): min channel index (%g) < 1.\n',...                       min(g.chans));    return  end;  if length(channelnos)>MAXPLOTDATACHANS,    fprintf('plottopo(): not set up to plot more than %d channels.\n',...                       MAXPLOTDATACHANS);    return  end;  if datasets>MAXPLOTDATAEPOCHS       fprintf('plottopo: not set up to plot more than %d epochs.\n',...                       MAXPLOTDATAEPOCHS);    return  end;  if datasets<1      fprintf('plottopo: cannot plot less than 1 epoch!\n');      return  end;  if ~isempty(g.geom)      if isnan(axheight) % if not specified          axheight = gcapos(4)/(g.geom(1)+1);          axwidth  = gcapos(3)/(g.geom(2)+1);      end      % if chan_locs(2) > 5      %     axwidth = 0.66/(chan_locs(2)+1);      % end  else      axheight = DEFAULT_AXHEIGHT;      axwidth =  DEFAULT_AXWIDTH;  end    fprintf('Plotting data using axis size [%g,%g]\n',axwidth,axheight);%%%%%%%%%%%%%% Extend the size of the plotting area in the window %%%%%%%%%%%%%  curfig = gcf;  h=figure(curfig);  set(h,'PaperUnits','normalized'); % use percentages to avoid US/A4 difference  set(h,'PaperPosition',[0.0235308 0.0272775 0.894169 0.909249]); % equivalent  orient portrait  axis('normal');  set(gca,'Color',BACKCOLOR);               % set the background color    axcolor= get(0,'DefaultAxesXcolor'); % find what the default x-axis color is  vertcolor = 'b';  plotfile = 'plottopo.ps';  ls_plotfile = 'ls -l plottopo.ps';    %%%%%%%%%%%%%%%%%%%%% Read the channel names %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if ~isstr(g.chans)     % channames = zeros(MAXPLOTDATACHANS,4);    % for c=1:length(g.chans),    %     channames(c,:)= sprintf('%4d',g.chans(c));    % end;    if length(g.chans) > 1 | g.chans(1) ~= 0        channames = num2str(g.chans(:));                   %%CJH    end;  else % isstr(g.chans)    if ~isstr(g.chans)       fprintf('plottopo(): channel file name must be a string.\n');       return    end    chid = fopen(g.chans,'r');    if chid <3,        fprintf('plottopo(): cannot open file %s.\n',g.chans);        return    else        fprintf('plottopo(): opened file %s.\n',g.chans);    end;    %%%%%%%    % fid=fopen('fgetl.m');    % while 1    %   line = fgetl(fid);    %   if ~isstr(line), break, end    %     disp(line)    %   end    % end    % fclose(fid);    %%%%%%%                           channames = fscanf(chid,'%s',[4 MAXPLOTDATACHANS]);    channames = channames';       [r c] = size(channames);    for i=1:r        for j=1:c            if channames(i,j)=='.',                channames(i,j)=' ';            end;        end;    end;  end; % setting channames%%%%%%%%%%%%%%%%%%%%%%%%%% Plot and label specified channels %%%%%%%%%%%%%%%%%%%data = data(channelnos,:);chans = length(channelnos);%%%%%%%%%%%%%%%%%%%%%%%%%% Read the color names %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if isstr(g.colors)      cid = fopen(g.colors,'r');      % fprintf('cid = %d\n',cid);      if cid <3,          fprintf('plottopo: cannot open file %s.\n',g.colors);          return      end;      g.colors = fscanf(cid,'%s',[3 MAXPLOTDATAEPOCHS]);      g.colors = g.colors';      [r c] = size(g.colors);      for i=1:r          for j=1:c              if g.colors(i,j)=='.',                  g.colors(i,j)=' ';              end;          end;      end;      g.colors = cellstr(g.colors);      for c=1:length(g.colors)   % make white traces black unless axis color is white          if g.colors{c}(1)=='w' & axcolor~=[1 1 1]              g.colors{c}(1)='k';          end      end  else % use default color order (no yellow!)      tmpcolors = { 'b' 'r' 'g' 'c' 'm' 'r' 'b' 'g' 'c' 'm' 'r' 'b' 'g' 'c' 'm' 'r' 'b' ...                   'g' 'c' 'm' 'r' 'b' 'g' 'c' 'm' 'r' 'b' 'g' 'c' 'm' 'r' 'b' 'g' 'c' 'm'};      g.colors = {g.colors{:} tmpcolors{:}};  % make > 64 available  end;%%%%%%%%%%%%%%%%%%%%%%%% Read and adjust limits %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if g.limits==0,      % == 0 or [0 0 0 0]    xmin=0;    xmax=g.frames-1;    ymin=min(min(data));    ymax=max(max(data));  else    if length(g.limits)~=4,      error('plottopo: limits should be 0 or an array [xmin xmax ymin ymax].\n');    end;    xmin = g.limits(1);    xmax = g.limits(2);    ymin = g.limits(3);    ymax = g.limits(4);  end;  if xmax == 0 & xmin == 0,    x = (0:1:g.frames-1);    xmin = 0;    xmax = g.frames-1;  else    dx = (xmax-xmin)/(g.frames-1);    x=xmin*ones(1,g.frames)+dx*(0:g.frames-1); % compute x-values  end;  if xmax<=xmin,      fprintf('plottopo() - xmax must be > xmin.\n')      return  end  if ymax == 0 & ymin == 0,      ymax=max(max(data));      ymin=min(min(data));  end  if ymax<=ymin,      fprintf('plottopo() - ymax must be > ymin.\n')      return  end  xlabel = 'Time (ms)';  if ISSPEC    ISSPEC = 1;    g.ydir = 1;    fprintf('Plotting positive up. Assuming data are spectra.\n');    xlabel = 'Freq (Hz)';    ymin = 0;                        % plot positive-up  end;%%%%%%%%%%%%%%%%%%%%%%% Set up plotting environment %%%%%%%%%%%%%%%%%%%%%%%%%%  % h = gcf;  % set(h,'YLim',[ymin ymax]);       % set default plotting parameters  % set(h,'XLim',[xmin xmax]);  % set(h,'FontSize',18);  % set(h,'DefaultLineLineWidth',1); % for thinner postscript lines%%%%%%%%%%%%%%%%%%%%%%%%%%% Print plot info %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  % clf;   % clear the current figure  % print plottitle over (left) subplot 1  h=gca;title(g.title,'FontSize',TITLEFONTSIZE); % title plot and  hold on  msg = ['Plotting %d traces of %d frames with colors: '];  for c=1:datasets      cind = mod(c-1, length(g.colors))+1;      if iscell(g.colors{cind})          msg = [msg  '''' g.colors{cind}{1} ''' ' ];      else          msg = [msg  '''' g.colors{cind} ''' ' ];      end;  end  msg = [msg '\n'];    % print starting info on screen . . .  fprintf('limits: [xmin,xmax,ymin,ymax] = [%4.1f %4.1f %4.2f %4.2f]\n',...                xmin,xmax,ymin,ymax);  fprintf(msg,datasets,g.frames);  set(h,'YLim',[ymin ymax]);            % set default plotting parameters  set(h,'XLim',[xmin xmax]);  set(h,'FontSize',FONTSIZE);           % choose font size  set(h,'FontSize',FONTSIZE);           % choose font size  set(h,'YLim',[ymin ymax]);            % set default plotting parameters  set(h,'XLim',[xmin xmax]);  axis('off')%%%%%%%%%%%%%%%%%%%%%%%%%%%% Read chan_locs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if isempty(g.chanlocs) % plot in a rectangular grid    ISRECT = 1;    ht = g.geom(1);    wd = g.geom(2);    if chans > ht*wd        fprintf('topoplot(): (%d) channels to be plotted > grid size [%d %d]\n',...                chans,ht,wd);        return    end    halfht = (ht-1)/2;    halfwd = (wd-1)/2;    xvals = zeros(ht*wd,1);    yvals = zeros(ht*wd,1);    dist  = zeros(ht*wd,1);    for j=1:ht          for i=1:wd            xvals(i+(j-1)*wd) = -halfwd+(i-1);            yvals(i+(j-1)*wd) =  halfht-(j-1);            % dist(i+(j-1)*wd) =  sqrt(xvals(j+(i-1)*ht).^2+yvals(j+(i-1)*ht).^2);        end    end    % maxdist = max(dist);    maxxvals = max(xvals);    maxyvals = max(yvals);    for j=1:ht        for i=1:wd            % xvals(i+(j-1)*wd) = 0.499*xvals(i+(j-1)*wd)/maxdist;             % yvals(i+(j-1)*wd) = 0.499*yvals(i+(j-1)*wd)/maxdist;             xvals(i+(j-1)*wd) = 0.499*xvals(i+(j-1)*wd)/maxxvals;             yvals(i+(j-1)*wd) = 0.499*yvals(i+(j-1)*wd)/maxyvals;         end    end    if ~exist('channames')        channames = repmat(' ',ht*wd,4);        for i=1:ht*wd            channum = num2str(i);            channames(i,1:length(channum)) = channum;        end    end    else % read chan_locs file     % read the channel location file     % ------------------------------    if isstruct(g.chanlocs)        nonemptychans = cellfun('isempty', { g.chanlocs.theta });        nonemptychans = find(~nonemptychans);        [tmp channames Th Rd] = readlocs(g.chanlocs(nonemptychans));        channames = strvcat({ g.chanlocs.labels });    else        [tmp channames Th Rd] = readlocs(g.chanlocs);        channames = strvcat(channames);        nonemptychans = [1:length(channames)];    end;	Th = pi/180*Th;                 % convert degrees to radians	Rd = Rd; 	    if length(channelnos) > length(g.chanlocs),        error('plottopo(): data channels must be <= ''chanlocs'' channels')

⌨️ 快捷键说明

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