topoimage.m

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

M
681
字号
% topoimage() - plot concatenated multichannel time/frequency images %               in a topographic format%               Uses a channel location file with the same format as topoplot() %               or else plots data on a rectangular grid of axes.%               Click on individual images to examine separately.%% Usage:%    >> topoimage(data,'chan_locs',ntimes,limits);%    >> topoimage(data,[rows cols],ntimes,limits);%    >> topoimage(data,'chan_locs',ntimes,limits,title,...%                                 channels,axsize,colors,ydir,rmbase) %% Inputs:%   data       = data consisting of nchans images, each size (rows,ntimes*chans) %  'chan_locs' = file of channel locations as in >> topoplot example%                Else [rows cols] matrix of locations. Example: [6 4]%   ntimes     = columns per image %  [limits]    = [mintime maxtime minfreq maxfreq mincaxis maxcaxis]  %                Give times in msec {default|0 (|both caxis 0) -> use data limits)%  'title'     = plot title {0 -> none}%   channels   = vector of channel numbers to plot & label {0 -> all}%   axsize     = [x y] axis size {default [.08 .07]}%  'colors'    = file of color codes, 3 chars per line  %                 ( '.' = space) {0 -> default color order}%   ydir       = y-axis polarity (pos-up = 1; neg-up = -1) {def -> pos-up}%   rmbase     = if ~=0, remove the mean value for times<=0 for each freq {def -> no}%% Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 12-10-1999%% See also: topoplot(), timef() %123456789012345678901234567890123456789012345678901234567890123456789012% Copyright (C) 12-10-99 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu%% This program is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA% $Log: topoimage.m,v $% Revision 1.1  2002/04/05 17:36:45  jorn% Initial revision%% 1-16-00  debugged help msg and improved presentation -sm% 3-16-00  added axcopy() -sm% 8-07-00  added logimagesc() via 'LOGIT' -sm% 9-02-00  added RMBASE option below, plus colorbar to key image -sm ???% 1-25-02  reformated help & license, added link -ad function topoimage(data,loc_file,times,limits,plottitle,channels,axsize,colors,ydr,rmbas)% Options:% LOGIT = 1; % comment out for non-log imaging% YVAL = 10;          % plot horizontal lines at 10 Hz (comment to omit)% RMBASE = 0;  % remove <0 mean for each image row MAXCHANS = 256;DEFAULT_AXWIDTH  = 0.08;DEFAULT_AXHEIGHT = 0.07;DEFAULT_SIGN = 1;   % Default - plot positive-upLINEWIDTH = 2.0;FONTSIZE = 14;      % font size to use for labelsCHANFONTSIZE = 10;  % font size to use for channel namesTICKFONTSIZE=10;    % font size to use for axis labelsTITLEFONTSIZE = 16;PLOT_WIDTH = 0.75;  % width and height of plot array on figure!PLOT_HEIGHT = 0.81;ISRECT = 0;         % defaultif nargin < 1,    help topoimage    returnendif nargin < 4,    help topoimage    error('topoimage(): needs four arguments');endif times <0,    help topoimage    returnelseif times==1,    fprintf('topoimage: cannot plot less than 2 times per image.\n');    returnelse    freqs = 0;end;axcolor= get(0,'DefaultAxesXcolor'); % find what the default x-axis color isplotfile = 'topoimage.ps';ls_plotfile = 'ls -l topoimage.ps';%%%%%%%%%%%%%%%%%%%%%%%%%%% Substitute defaults for missing parameters %%%%%%SIGN = DEFAULT_SIGN;if nargin < 10   rmbas = 0;endif nargin < 9   ydr = 0;endif ydr == -1   SIGN = -1;end  if nargin < 8    colors = 0;endif nargin < 7,  axwidth  = DEFAULT_AXWIDTH;  axheight = DEFAULT_AXHEIGHT;elseif size(axsize) == [1 1] & axsize(1) == 0  axwidth  = DEFAULT_AXWIDTH;  axheight = DEFAULT_AXHEIGHT;elseif size(axsize) == [1 2]  axwidth  = axsize(1);  axheight = axsize(2);  if axwidth > 1 | axwidth < 0 | axheight > 1 | axwidth < 0    help topoimage    return  endelse  help topoimage  returnend[freqs,framestotal]=size(data);             % data sizechans = framestotal/times;fprintf('\nPlotting data using axis size [%g,%g]\n',axwidth,axheight);if nargin < 6   channels = 0;endif channels == 0   channels = 1:chans;endif nargin < 5    plottitle = 0; %CJHendlimitset = 0;if nargin < 4,    limits = 0;elseif length(limits)>1    limitset = 1;end    %%%%%%%%%%%%%%%%%%%%%%%%%%% Test parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  icadefs; % read MAXPLOTDATACHANS constant from icadefs.m  if max(channels) > chans    fprintf('topoimage(): max channel index > %d channels in data.\n',...                       chans);    return  end  if min(channels) < 1    fprintf('topoimage(): min channel index (%g) < 1.\n',...                       min(channels));    return  end;  if length(channels)>MAXPLOTDATACHANS,    fprintf('topoimage(): not set up to plot more than %d channels.\n',...                       MAXPLOTDATACHANS);    return  end;%%%%%%%%%%%%%% Extend the size of the plotting area in the window %%%%%%%%%%%%%  curfig = gcf;  h=figure(curfig);  set(h,'Color',BACKCOLOR); % set the background color  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');%%%%%%%%%%%%%%%%%%%%% Read the channel names %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if isstr(channels) == 0,    % channames = zeros(MAXPLOTDATACHANS,4);    % for c=1:length(channels),    %     channames(c,:)= sprintf('%4d',channels(c));    % end;    channames = num2str(channels(:));                   %%CJH  else,    if ~isstr(channels)       fprintf('topoimage(): channel file name must be a string.\n');       return    end    chid = fopen(channels,'r');    if chid <3,        fprintf('topoimage(): cannot open file %s.\n',channels);        return    end;    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 = matsel(data,times,0,0,channels);chans = length(channels);%%%%%%%%%%%%%%%%%%%%%%%%%% Read the color names %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if colors ~=0,    if ~isstr(colors)       fprintf('topoimage(): color file name must be a string.\n');       return    end    cid = fopen(colors,'r');    % fprintf('cid = %d\n',cid);    if cid <3,        fprintf('topoimage: cannot open file %s.\n',colors);        return    end;    colors = fscanf(cid,'%s',[3 MAXPLOTDATAEPOCHS]);    colors = colors';       [r c] = size(colors);    for i=1:r        for j=1:c            if colors(i,j)=='.',                colors(i,j)=' ';            end;        end;    end;  else % use default color order (no yellow!)     colors =['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  ';'r  ';'b  ';'g  ';'c  ';'m  '];     colors = [colors; colors];  % make > 64 available  end;  for c=1:length(colors)   % make white traces black unless axis color is white    if colors(c,1)=='w' & axcolor~=[1 1 1]         colors(c,1)='k';    end  end%%%%%%%%%%%%%%%%%%%%%%%% Read and adjust limits %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  if limits==0,      % == 0 or [0 0 0 0]    xmin=min(times);    xmax=max(times);    ymin=min(freqs);    ymax=max(freqs);  else    if length(limits)~=6,      fprintf( ...       'topoimage: limits should be 0 or an array [xmin xmax ymin ymax zmin zmax].\n');      return    end;    xmin = limits(1);    xmax = limits(2);    ymin = limits(3);    ymax = limits(4);    zmin = limits(5);    zmax = limits(6);  end;  if xmax == 0 & xmin == 0,    x = [0:1:times-1];    xmin = min(x);    xmax = max(x);  else    dx = (xmax-xmin)/(times-1);    x=xmin*ones(1,times)+dx*(0:times-1); % compute x-values    xmax = xmax*times/times;  end;  if xmax<=xmin,      fprintf('topoimage() - xmax must be > xmin.\n')      return  end  if ymax == 0 & ymin == 0,      y=[1:1:freqs];      ymax=freqs;      ymin=1;  else    dy = (ymax-ymin)/(freqs-1);    y=ymin*ones(1,freqs)+dy*(0:freqs-1); % compute y-values    ymax = max(y);  end  if ymax<=ymin,      fprintf('topoimage() - ymax must be > ymin.\n')      return  end  if zmax == 0 & zmin == 0,      zmax=max(max(data));      zmin=min(min(data));      fprintf('Color axis limits [%g,%g]\n',zmin,zmax);  end  if zmax<=zmin,      fprintf('topoimage() - zmax must be > zmin.\n')      return  end  xlabel = 'Time (ms)';  ylabel = 'Hz';%%%%%%%%%%%%%%%%%%%%%%%%% 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  if plottitle==0,    plottitle = '';  end  h=gca;title(plottitle,'FontSize',TITLEFONTSIZE); % title plot and  hold on  msg = ['\nPlotting %d traces of %d frames with colors: '];

⌨️ 快捷键说明

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