Home > matlabmk > topoplotMK.m

topoplotMK

PURPOSE ^

topoplotMK() - plot a topographic map of a scalp data field in a 2-D circular view

SYNOPSIS ^

function [handle,Zi,grid,Xi,Yi] = topoplotMK(Values,loc_file,varargin)

DESCRIPTION ^

 topoplotMK() - plot a topographic map of a scalp data field in a 2-D circular view
                (looking down at the top of the head) using interpolation on a fine
                cartesian grid. Can also show specified channnel location(s), or return
                an interpolated value at an arbitrary scalp location (see 'noplot').
                By default, channel locations below head center (arc_length 0.5) are
                shown in a 'skirt' outside the cartoon head (see 'plotrad' and 'headrad'
                options below). Nose is at top of plot; left is left; right is right.
                Using option 'plotgrid', the plot may be one or more
                rectangular grids. Same as default EEGLAB topoplot
                function but with a few additional arguments.
 Usage:
        >>  topoplot(datavector, EEG.chanlocs);   % plot a map using an EEG chanlocs structure
        >>  topoplot(datavector, 'my_chan.locs'); % read a channel locations file and plot a map
        >>  topoplot('example');                  % give an example of an electrode location file
        >>  [h grid_or_val plotrad_or_grid, xmesh, ymesh]= ...
                           topoplot(datavector, chan_locs, 'Input1','Value1', ...);
 Required Inputs:
   datavector        - single vector of channel values. Else, if a vector of selected subset
                       (int) channel numbers -> mark their location(s) using 'style' 'blank'.
   chan_locs         - name of an EEG electrode position file (>> topoplot example).
                       Else, an EEG.chanlocs structure (>> help readlocs or >> topoplot example)
 Optional inputs:
   'maplimits'       - 'absmax'   -> scale map colors to +/- the absolute-max (makes green 0);
                       'maxmin'   -> scale colors to the data range (makes green mid-range);
                       [lo.hi]    -> use user-definined lo/hi limits
                       {default: 'absmax'}
   'style'           - 'map'      -> plot colored map only
                       'contour'  -> plot contour lines only
                       'both'     -> plot both colored map and contour lines
                       'fill'     -> plot constant color between contour lines
                       'blank'    -> plot electrode locations only {default: 'both'}
   'electrodes'      - 'on','off','labels','numbers','ptslabels','ptsnumbers'. To set the 'pts'
                       marker,,see 'Plot detail options' below. {default: 'on' -> mark electrode
                       locations with points ('.') unless more than 64 channels, then 'off'}.
   'plotchans'       - [vector] channel numbers (indices) to use in making the head plot.
                       {default: [] -> plot all chans}
   'chantype'        - cell array of channel type(s) to plot. Will also accept a single quoted
                       string type. Channel type for channel k is field EEG.chanlocs(k).type.
                       If present, overrides 'plotchans' and also 'chaninfo' with field
                       'chantype'. Ex. 'EEG' or {'EEG','EOG'} {default: all, or 'plotchans' arg}
   'plotgrid'        - [channels] Plot channel data in one or more rectangular grids, as
                       specified by [channels],  a position matrix of channel numbers defining
                       the topographic locations of the channels in the grid. Zero values are
                       given the figure background color; negative integers, the color of the
                       polarity-reversed channel values.  Ex: >> figure; ...
                        >> topoplot(values,'chanlocs','plotgrid',[11 12 0; 13 14 15]);
                       % Plot a (2,3) grid of data values from channels 11-15 with one empty
                       grid cell (top right) {default: no grid plot}
   'nosedir'         - ['+X'|'-X'|'+Y'|'-Y'] direction of nose {default: '+X'}
   'chaninfo'        - [struct] optional structure containing fields 'nosedir', 'plotrad'
                       and/or 'chantype'. See these (separate) field definitions above, below.
                       {default: nosedir +X, plotrad 0.5, all channels}
   'plotrad'         - [0.15<=float<=1.0] plotting radius = max channel arc_length to plot.
                       See >> topoplot example. If plotrad > 0.5, chans with arc_length > 0.5
                       (i.e. below ears-eyes) are plotted in a circular 'skirt' outside the
                       cartoon head. See 'intrad' below. {default: max(max(chanlocs.radius),0.5);
                       If the chanlocs structure includes a field chanlocs.plotrad, its value
                       is used by default}.
   'headrad'         - [0.15<=float<=1.0] drawing radius (arc_length) for the cartoon head.
                       NOTE: Only headrad = 0.5 is anatomically correct! 0 -> don't draw head;
                       'rim' -> show cartoon head at outer edge of the plot {default: 0.5}
   'intrad'          - [0.15<=float<=1.0] radius of the scalp map interpolation area (square or
                       disk, see 'intsquare' below). Interpolate electrodes in this area and use
                       this limit to define boundaries of the scalp map interpolated data matrix
                       {default: max channel location radius}
   'intsquare'       - ['on'|'off'] 'on' -> Interpolate values at electrodes located in the whole
                       square containing the (radius intrad) interpolation disk; 'off' -> Interpolate
                       values from electrodes shown in the interpolation disk only {default: 'on'}.
   'conv'            - ['on'|'off'] Show map interpolation only out to the convext hull of
                       the electrode locations to minimize extrapolation.  {default: 'off'}
   'noplot'          - ['on'|'off'|[rad theta]] do not plot (but return interpolated data).
                       Else, if [rad theta] are coordinates of a (possibly missing) channel,
                       returns interpolated value for channel location.  For more info,
                       see >> topoplot 'example' {default: 'off'}
   'verbose'         - ['on'|'off'] comment on operations on command line {default: 'on'}.

 Plot detail options:
   'drawaxis'        - ['on'|'off'] draw axis on the top left corner.
   'emarker'         - Matlab marker char | {markerchar color size linewidth} char, else cell array
                       specifying the electrode 'pts' marker. Ex: {'s','r',32,1} -> 32-point solid
                       red square. {default: {'.','k',[],1} where marker size ([]) depends on the number
                       of channels plotted}.
   'emarker2'        - {markchans}|{markchans marker color size linewidth} cell array specifying
                       an alternate marker for specified 'plotchans'. Ex: {[3 17],'s','g'}
                       {default: none, or if {markchans} only are specified, then {markchans,'o','r',10,1}}
   'hcolor'          - color of the cartoon head. Use 'hcolor','none' to plot no head. {default: 'k' = black}
   'shading'         - 'flat','interp'  {default: 'flat'}
   'numcontour'      - number of contour lines {default: 6}
   'contourvals'     - values for contour {default: same as input values}
   'pmask'           - values for masking topoplot. Array of zeros and 1 of the same size as the input
                       value array {default: []}
   'color'           - color of the contours {default: dark grey}
   'whitebk '        -  ('on'|'off') make the background color white (e.g., to print empty plotgrid channels)
                       {default: 'off'}
   'gridscale'       - [int > 32] size (nrows) of interpolated scalp map data matrix {default: 67}
   'colormap'        -  (n,3) any size colormap {default: existing colormap}
   'circgrid'        - [int > 100] number of elements (angles) in head and border circles {201}
   'plain_blank'     - [0 | 1] If 1, the plot of the topography is slightly altered when the 
                       optional input 'style' is set to 'blank'. Specifically, the 'emarker2' 
                       option is allowed, red disks are not drawn over electrodes, and the extra 
                       text (e.g., the title 'Channel Locations') is not drawn. {default: 0}

 Dipole plotting options:
   'dipole'          - [xi yi xe ye ze] plot dipole on the top of the scalp map
                       from coordinate (xi,yi) to coordinates (xe,ye,ze) (dipole head
                       model has radius 1). If several rows, plot one dipole per row.
                       Coordinates returned by dipplot() may be used. Can accept
                       an EEG.dipfit.model structure (See >> help dipplot).
                       Ex: ,'dipole',EEG.dipfit.model(17) % Plot dipole(s) for comp. 17.
   'dipnorm'         - ['on'|'off'] normalize dipole length {default: 'on'}.
   'diporient'       - [-1|1] invert dipole orientation {default: 1}.
   'diplen'          - [real] scale dipole length {default: 1}.
   'dipscale'        - [real] scale dipole size {default: 1}.
   'dipsphere'       - [real] size of the dipole sphere. {default: 85 mm}.
   'dipcolor'        - [color] dipole color as Matlab code code or [r g b] vector
                       {default: 'k' = black}.
 Outputs:
                   h - plot axes handle
         grid_or_val - [matrix] the interpolated data image (with off-head points = NaN).
                       Else, single interpolated value at the specified 'noplot' arg channel
                       location ([rad theta]), if any.
     plotrad_or_grid - IF grid image returned above, then the 'plotrad' radius of the grid.
                       Else, the grid image
     xmesh, ymesh    - x and y values of the returned grid (above)

 Chan_locs format:
    See >> topoplot 'example'

 Examples:

    To plot channel locations only:
    >> figure; topoplot([],EEG.chanlocs,'style','blank','electrodes','labelpoint','chaninfo',EEG.chaninfo);

 Notes: - To change the plot map masking ring to a new figure background color,
            >> set(findobj(gca,'type','patch'),'facecolor',get(gcf,'color'))
        - Topoplots may be rotated. From the commandline >> view([deg 90]) {default: [0 90])

 Authors: Andy Spydell, Colin Humphries, Arnaud Delorme & Scott Makeig
          CNL / Salk Institute, 8/1996-/10/2001; SCCN/INC/UCSD, Nov. 2001 -

 See also: timtopo(), envtopo()

 NOTE: This is a slightly modified version of EEGLAB's topoplot.m.  It has
 some additional arguments and functionality that are needed by the Mass
 Univariate ERP Toolbox.  Search "DG" to find changes. <-David Groppe

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % topoplotMK() - plot a topographic map of a scalp data field in a 2-D circular view
0002 %                (looking down at the top of the head) using interpolation on a fine
0003 %                cartesian grid. Can also show specified channnel location(s), or return
0004 %                an interpolated value at an arbitrary scalp location (see 'noplot').
0005 %                By default, channel locations below head center (arc_length 0.5) are
0006 %                shown in a 'skirt' outside the cartoon head (see 'plotrad' and 'headrad'
0007 %                options below). Nose is at top of plot; left is left; right is right.
0008 %                Using option 'plotgrid', the plot may be one or more
0009 %                rectangular grids. Same as default EEGLAB topoplot
0010 %                function but with a few additional arguments.
0011 % Usage:
0012 %        >>  topoplot(datavector, EEG.chanlocs);   % plot a map using an EEG chanlocs structure
0013 %        >>  topoplot(datavector, 'my_chan.locs'); % read a channel locations file and plot a map
0014 %        >>  topoplot('example');                  % give an example of an electrode location file
0015 %        >>  [h grid_or_val plotrad_or_grid, xmesh, ymesh]= ...
0016 %                           topoplot(datavector, chan_locs, 'Input1','Value1', ...);
0017 % Required Inputs:
0018 %   datavector        - single vector of channel values. Else, if a vector of selected subset
0019 %                       (int) channel numbers -> mark their location(s) using 'style' 'blank'.
0020 %   chan_locs         - name of an EEG electrode position file (>> topoplot example).
0021 %                       Else, an EEG.chanlocs structure (>> help readlocs or >> topoplot example)
0022 % Optional inputs:
0023 %   'maplimits'       - 'absmax'   -> scale map colors to +/- the absolute-max (makes green 0);
0024 %                       'maxmin'   -> scale colors to the data range (makes green mid-range);
0025 %                       [lo.hi]    -> use user-definined lo/hi limits
0026 %                       {default: 'absmax'}
0027 %   'style'           - 'map'      -> plot colored map only
0028 %                       'contour'  -> plot contour lines only
0029 %                       'both'     -> plot both colored map and contour lines
0030 %                       'fill'     -> plot constant color between contour lines
0031 %                       'blank'    -> plot electrode locations only {default: 'both'}
0032 %   'electrodes'      - 'on','off','labels','numbers','ptslabels','ptsnumbers'. To set the 'pts'
0033 %                       marker,,see 'Plot detail options' below. {default: 'on' -> mark electrode
0034 %                       locations with points ('.') unless more than 64 channels, then 'off'}.
0035 %   'plotchans'       - [vector] channel numbers (indices) to use in making the head plot.
0036 %                       {default: [] -> plot all chans}
0037 %   'chantype'        - cell array of channel type(s) to plot. Will also accept a single quoted
0038 %                       string type. Channel type for channel k is field EEG.chanlocs(k).type.
0039 %                       If present, overrides 'plotchans' and also 'chaninfo' with field
0040 %                       'chantype'. Ex. 'EEG' or {'EEG','EOG'} {default: all, or 'plotchans' arg}
0041 %   'plotgrid'        - [channels] Plot channel data in one or more rectangular grids, as
0042 %                       specified by [channels],  a position matrix of channel numbers defining
0043 %                       the topographic locations of the channels in the grid. Zero values are
0044 %                       given the figure background color; negative integers, the color of the
0045 %                       polarity-reversed channel values.  Ex: >> figure; ...
0046 %                        >> topoplot(values,'chanlocs','plotgrid',[11 12 0; 13 14 15]);
0047 %                       % Plot a (2,3) grid of data values from channels 11-15 with one empty
0048 %                       grid cell (top right) {default: no grid plot}
0049 %   'nosedir'         - ['+X'|'-X'|'+Y'|'-Y'] direction of nose {default: '+X'}
0050 %   'chaninfo'        - [struct] optional structure containing fields 'nosedir', 'plotrad'
0051 %                       and/or 'chantype'. See these (separate) field definitions above, below.
0052 %                       {default: nosedir +X, plotrad 0.5, all channels}
0053 %   'plotrad'         - [0.15<=float<=1.0] plotting radius = max channel arc_length to plot.
0054 %                       See >> topoplot example. If plotrad > 0.5, chans with arc_length > 0.5
0055 %                       (i.e. below ears-eyes) are plotted in a circular 'skirt' outside the
0056 %                       cartoon head. See 'intrad' below. {default: max(max(chanlocs.radius),0.5);
0057 %                       If the chanlocs structure includes a field chanlocs.plotrad, its value
0058 %                       is used by default}.
0059 %   'headrad'         - [0.15<=float<=1.0] drawing radius (arc_length) for the cartoon head.
0060 %                       NOTE: Only headrad = 0.5 is anatomically correct! 0 -> don't draw head;
0061 %                       'rim' -> show cartoon head at outer edge of the plot {default: 0.5}
0062 %   'intrad'          - [0.15<=float<=1.0] radius of the scalp map interpolation area (square or
0063 %                       disk, see 'intsquare' below). Interpolate electrodes in this area and use
0064 %                       this limit to define boundaries of the scalp map interpolated data matrix
0065 %                       {default: max channel location radius}
0066 %   'intsquare'       - ['on'|'off'] 'on' -> Interpolate values at electrodes located in the whole
0067 %                       square containing the (radius intrad) interpolation disk; 'off' -> Interpolate
0068 %                       values from electrodes shown in the interpolation disk only {default: 'on'}.
0069 %   'conv'            - ['on'|'off'] Show map interpolation only out to the convext hull of
0070 %                       the electrode locations to minimize extrapolation.  {default: 'off'}
0071 %   'noplot'          - ['on'|'off'|[rad theta]] do not plot (but return interpolated data).
0072 %                       Else, if [rad theta] are coordinates of a (possibly missing) channel,
0073 %                       returns interpolated value for channel location.  For more info,
0074 %                       see >> topoplot 'example' {default: 'off'}
0075 %   'verbose'         - ['on'|'off'] comment on operations on command line {default: 'on'}.
0076 %
0077 % Plot detail options:
0078 %   'drawaxis'        - ['on'|'off'] draw axis on the top left corner.
0079 %   'emarker'         - Matlab marker char | {markerchar color size linewidth} char, else cell array
0080 %                       specifying the electrode 'pts' marker. Ex: {'s','r',32,1} -> 32-point solid
0081 %                       red square. {default: {'.','k',[],1} where marker size ([]) depends on the number
0082 %                       of channels plotted}.
0083 %   'emarker2'        - {markchans}|{markchans marker color size linewidth} cell array specifying
0084 %                       an alternate marker for specified 'plotchans'. Ex: {[3 17],'s','g'}
0085 %                       {default: none, or if {markchans} only are specified, then {markchans,'o','r',10,1}}
0086 %   'hcolor'          - color of the cartoon head. Use 'hcolor','none' to plot no head. {default: 'k' = black}
0087 %   'shading'         - 'flat','interp'  {default: 'flat'}
0088 %   'numcontour'      - number of contour lines {default: 6}
0089 %   'contourvals'     - values for contour {default: same as input values}
0090 %   'pmask'           - values for masking topoplot. Array of zeros and 1 of the same size as the input
0091 %                       value array {default: []}
0092 %   'color'           - color of the contours {default: dark grey}
0093 %   'whitebk '        -  ('on'|'off') make the background color white (e.g., to print empty plotgrid channels)
0094 %                       {default: 'off'}
0095 %   'gridscale'       - [int > 32] size (nrows) of interpolated scalp map data matrix {default: 67}
0096 %   'colormap'        -  (n,3) any size colormap {default: existing colormap}
0097 %   'circgrid'        - [int > 100] number of elements (angles) in head and border circles {201}
0098 %   'plain_blank'     - [0 | 1] If 1, the plot of the topography is slightly altered when the
0099 %                       optional input 'style' is set to 'blank'. Specifically, the 'emarker2'
0100 %                       option is allowed, red disks are not drawn over electrodes, and the extra
0101 %                       text (e.g., the title 'Channel Locations') is not drawn. {default: 0}
0102 %
0103 % Dipole plotting options:
0104 %   'dipole'          - [xi yi xe ye ze] plot dipole on the top of the scalp map
0105 %                       from coordinate (xi,yi) to coordinates (xe,ye,ze) (dipole head
0106 %                       model has radius 1). If several rows, plot one dipole per row.
0107 %                       Coordinates returned by dipplot() may be used. Can accept
0108 %                       an EEG.dipfit.model structure (See >> help dipplot).
0109 %                       Ex: ,'dipole',EEG.dipfit.model(17) % Plot dipole(s) for comp. 17.
0110 %   'dipnorm'         - ['on'|'off'] normalize dipole length {default: 'on'}.
0111 %   'diporient'       - [-1|1] invert dipole orientation {default: 1}.
0112 %   'diplen'          - [real] scale dipole length {default: 1}.
0113 %   'dipscale'        - [real] scale dipole size {default: 1}.
0114 %   'dipsphere'       - [real] size of the dipole sphere. {default: 85 mm}.
0115 %   'dipcolor'        - [color] dipole color as Matlab code code or [r g b] vector
0116 %                       {default: 'k' = black}.
0117 % Outputs:
0118 %                   h - plot axes handle
0119 %         grid_or_val - [matrix] the interpolated data image (with off-head points = NaN).
0120 %                       Else, single interpolated value at the specified 'noplot' arg channel
0121 %                       location ([rad theta]), if any.
0122 %     plotrad_or_grid - IF grid image returned above, then the 'plotrad' radius of the grid.
0123 %                       Else, the grid image
0124 %     xmesh, ymesh    - x and y values of the returned grid (above)
0125 %
0126 % Chan_locs format:
0127 %    See >> topoplot 'example'
0128 %
0129 % Examples:
0130 %
0131 %    To plot channel locations only:
0132 %    >> figure; topoplot([],EEG.chanlocs,'style','blank','electrodes','labelpoint','chaninfo',EEG.chaninfo);
0133 %
0134 % Notes: - To change the plot map masking ring to a new figure background color,
0135 %            >> set(findobj(gca,'type','patch'),'facecolor',get(gcf,'color'))
0136 %        - Topoplots may be rotated. From the commandline >> view([deg 90]) {default: [0 90])
0137 %
0138 % Authors: Andy Spydell, Colin Humphries, Arnaud Delorme & Scott Makeig
0139 %          CNL / Salk Institute, 8/1996-/10/2001; SCCN/INC/UCSD, Nov. 2001 -
0140 %
0141 % See also: timtopo(), envtopo()
0142 %
0143 % NOTE: This is a slightly modified version of EEGLAB's topoplot.m.  It has
0144 % some additional arguments and functionality that are needed by the Mass
0145 % Univariate ERP Toolbox.  Search "DG" to find changes. <-David Groppe
0146 %
0147 
0148 % Deprecated options:
0149 %           'shrink' - ['on'|'off'|'force'|factor] Deprecated. 'on' -> If max channel arc_length
0150 %                       > 0.5, shrink electrode coordinates towards vertex to plot all channels
0151 %                       by making max arc_length 0.5. 'force' -> Normalize arc_length
0152 %                       so the channel max is 0.5. factor -> Apply a specified shrink
0153 %                       factor (range (0,1) = shrink fraction). {default: 'off'}
0154 %   'electcolor' {'k'}  ... electrode marking details and their {defaults}.
0155 %   'emarker' {'.'}|'emarkersize' {14}|'emarkersizemark' {40}|'efontsize' {var} -
0156 %                       electrode marking details and their {defaults}.
0157 %   'ecolor'          - color of the electrode markers {default: 'k' = black}
0158 %   'interplimits'    - ['electrodes'|'head'] 'electrodes'-> interpolate the electrode grid;
0159 %                       'head'-> interpolate the whole disk {default: 'head'}.
0160 
0161 % Unimplemented future options:
0162 
0163 % Copyright (C) Colin Humphries & Scott Makeig, CNL / Salk Institute, Aug, 1996
0164 %
0165 % This program is free software;
0166 %
0167 % This program is distributed in the hope that it will be useful,
0168 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0169 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0170 
0171 % $Log: topoplot.m,v $
0172 % Revision 1.288  2009/08/09 04:57:25  arno
0173 % change transparency
0174 %
0175 % Revision 1.287  2009/05/17 21:53:04  arno
0176 % add pmask and contourvals option
0177 %
0178 % Revision 1.286  2008/12/20 00:45:10  arno
0179 % revert 1.284
0180 %
0181 % Revision 1.284  2008/04/19 21:01:34  arno
0182 % fix 'example'.
0183 %
0184 % Revision 1.283  2008/01/10 01:24:55  nima
0185 % dipole direction line problem fixed.
0186 %
0187 % Revision 1.282  2007/11/29 17:49:56  arno
0188 % header typo
0189 %
0190 % Revision 1.281  2007/09/11 10:57:53  arno
0191 % catch error when plotting channels outside bounadries
0192 %
0193 % Revision 1.280  2007/08/08 17:50:55  arno
0194 % fix typo
0195 %
0196 % Revision 1.279  2007/08/08 17:38:13  arno
0197 % handle better fieldtrip
0198 %
0199 % Revision 1.278  2007/08/07 21:33:01  arno
0200 % remove debug message
0201 %
0202 % Revision 1.277  2007/08/07 21:22:34  arno
0203 % changed optional arguments to use varargin, call topoplot from fieldtrip if necessary
0204 %
0205 % Revision 1.276  2007/02/05 20:25:58  toby
0206 % fixed bug when entering channels to plot instead of channel values as the first Input
0207 %
0208 % Revision 1.275  2006/09/14 09:31:43  arno
0209 % fix the white background command
0210 %
0211 % Revision 1.274  2006/07/21 03:05:34  toby
0212 % *** empty log message ***
0213 %
0214 % Revision 1.273  2006/07/21 02:44:48  toby
0215 % commented out faulty error message
0216 %
0217 % Revision 1.272  2006/05/07 18:10:15  arno
0218 % channels indices were not accurate -> fixing them
0219 %
0220 % Revision 1.271  2006/04/12 02:54:13  toby
0221 % help text edit
0222 %
0223 % Revision 1.270  2006/03/13 22:44:32  arno
0224 % change default marker
0225 %
0226 % Revision 1.269  2006/03/09 17:15:37  arno
0227 % change default marker size
0228 % /
0229 %
0230 % Revision 1.268  2006/01/17 23:01:27  scott
0231 % clarified status of 'plotgrid' -sm
0232 %
0233 % Revision 1.267  2005/12/08 00:22:19  arno
0234 % fixing ploting one channel
0235 %
0236 % Revision 1.266  2005/12/01 20:28:29  arno
0237 % typo
0238 %
0239 % Revision 1.265  2005/11/30 19:07:58  arno
0240 % fixing ploting electrodes only
0241 %
0242 % Revision 1.264  2005/11/30 19:02:40  arno
0243 % generic plotchan
0244 %
0245 % Revision 1.263  2005/11/21 21:30:08  toby
0246 % Corrected a crash-error when attempting to use "plotgrid" and "maplimit>absmax" options
0247 %
0248 % Revision 1.262  2005/11/11 00:58:03  arno
0249 % nothing
0250 %
0251 % Revision 1.261  2005/10/29 03:57:01  scott
0252 % chantype help
0253 %
0254 % Revision 1.260  2005/10/27 22:00:26  toby
0255 % adding channel type
0256 %
0257 % Revision 1.258  2005/09/29 14:56:41  scott
0258 % nothing
0259 %
0260 % Revision 1.257  2005/09/27 21:59:49  arno
0261 % fix plotrad issue call from pop_chanedit
0262 %
0263 % Revision 1.256  2005/09/05 15:58:14  scott
0264 % nothing - spacing while looking through code -sm
0265 %
0266 % Revision 1.255  2005/07/27 18:12:59  arno
0267 % removing datachan check
0268 %
0269 % Revision 1.254  2005/07/16 16:36:08  scott
0270 % same
0271 %
0272 % Revision 1.253  2005/07/16 16:27:25  scott
0273 % fixed 'maplimits',[min max] execution, added test -sm
0274 %
0275 % Revision 1.252  2005/07/12 17:03:25  scott
0276 % documented 'whitebk' option -sm
0277 %
0278 % Revision 1.251  2005/06/09 23:33:46  arno
0279 % remove getdatachan function
0280 %
0281 % Revision 1.250  2005/06/09 23:33:21  arno
0282 % fixing datachan
0283 %
0284 % Revision 1.249  2005/06/09 16:36:25  arno
0285 % getdatachans
0286 %
0287 % Revision 1.248  2005/03/09 17:08:03  arno
0288 % implementing nosedir
0289 %
0290 % Revision 1.247  2005/03/07 17:11:19  arno
0291 % implement chaninfo
0292 %
0293 % Revision 1.246  2005/01/28 17:26:10  arno
0294 % fix typo
0295 %
0296 % Revision 1.245  2005/01/25 18:47:01  scott
0297 % fixed recent bug that made all topoplot colors positive!!
0298 % worked on bug when removing gridchans from specified plotchans (using setxor)
0299 %
0300 % Revision 1.244  2005/01/25 01:32:53  scott
0301 % help msg
0302 %
0303 % Revision 1.243  2005/01/10 20:26:34  scott
0304 % adjust color limits for 'gridplot'
0305 %
0306 % Revision 1.242  2005/01/10 19:46:47  scott
0307 % added (undoc) arg 'whitebk'
0308 %
0309 % Revision 1.241  2005/01/07 22:39:40  scott
0310 % fixed 'labelpoint' keyword for 'electrodes' (used in eeglab.m)
0311 %
0312 % Revision 1.240  2005/01/07 19:55:47  scott
0313 % remove traces of 'gridpos'
0314 %
0315 % Revision 1.239  2005/01/06 19:27:17  scott
0316 % implemented 'gridplot' | 'plotgrid' option
0317 %
0318 % Revision 1.238  2005/01/03 02:27:32  scott
0319 % made 'grid' rectangular (each element square)
0320 %
0321 % Revision 1.237  2005/01/03 02:10:33  scott
0322 % added 'gridplot' option
0323 %
0324 % Revision 1.236  2005/01/02 18:42:25  scott
0325 % implementing 'plotgrid'
0326 %
0327 % Revision 1.235  2004/12/26 05:48:57  scott
0328 % enlarged definition of 'emarker', deprecated 'ecolor','emarkersize'...
0329 %
0330 % Revision 1.234  2004/12/24 19:48:23  scott
0331 % fixed and extended 'emarker2' args; added 'hcolor','none' option; changed 'emarkersize1chan' to
0332 % 'emarkersizemark' (preserving backwards compatability as well). tested with /home/www/eeglab/test_topoplot.m
0333 %
0334 % Revision 1.233  2004/12/24 01:32:29  scott
0335 % documented xmesh, ymesh optional outputs
0336 %
0337 % Revision 1.232  2004/12/24 01:25:28  scott
0338 % clarified 'plotchans', added 'emarker2'
0339 %
0340 % Revision 1.231  2004/12/21 23:18:48  hilit
0341 % change x and y axis to depend on squeezfac, in case 'intrad' is provided
0342 %
0343 % Revision 1.230  2004/12/20 22:05:44  scott
0344 % if intrad specified, then make plotrad <= intrad
0345 %
0346 % Revision 1.229  2004/12/20 21:13:41  scott
0347 % made specifying 'intrad' -> actually use intrad to define the interp grid.
0348 % returned Xi, Yi for toporeplot() (undocumented)
0349 %
0350 % Revision 1.228  2004/12/17 16:36:53  scott
0351 % cleaning up 'plotgrid' code
0352 %
0353 % Revision 1.227  2004/12/17 06:49:57  scott
0354 % tested if isstruct or string chan_loc; worked on plotgrid - still unimplemented
0355 %
0356 % Revision 1.226  2004/12/10 21:00:17  scott
0357 % made 3rd output plotrad (by default). Documented reading of chanlocs.plotrad
0358 % if it exists.
0359 %
0360 % Revision 1.225  2004/11/23 01:52:12  hilit
0361 % fixing 'style' 'blank' problems
0362 %
0363 % Revision 1.224  2004/11/22 21:55:46  hilit
0364 % undo some of the changes
0365 %
0366 % Revision 1.223  2004/11/22 21:47:14  hilit
0367 % debugging 'style' 'blank' problems
0368 %
0369 % Revision 1.222  2004/11/22 20:11:38  scott
0370 % trying to fix style 'blank' problems
0371 %
0372 % Revision 1.221  2004/11/22 05:41:43  arno
0373 % more debugging
0374 %
0375 % Revision 1.220  2004/11/22 05:39:05  arno
0376 % function was crashing on regular topoplot, debuging
0377 %
0378 % Revision 1.219  2004/11/22 05:02:51  scott
0379 % fixing topoplot([],EEG.chanlocs,'emarker','o')
0380 %
0381 % Revision 1.218  2004/11/22 04:58:21  scott
0382 % fixed topoplot(32,EEG.chanlocs) and topoplot([],EEG.chanlocs,'emarker','o')
0383 % to plot marked channel 32 in red disk
0384 %
0385 % Revision 1.217  2004/11/18 20:29:14  hilit
0386 % enabled the 'example' option
0387 %
0388 % Revision 1.216  2004/11/18 19:22:22  scott
0389 % made 3rd output, 'grid'. [] unless interpolated value asked for
0390 %
0391 % Revision 1.215  2004/11/09 19:25:08  arno
0392 % move plotgrid help outsie of header since unimplemented
0393 %
0394 % Revision 1.214  2004/10/27 17:34:35  scott
0395 % help msg adjust -sm
0396 %
0397 % Revision 1.213  2004/10/27 16:39:06  arno
0398 % remove infinite and NaN values
0399 %
0400 % Revision 1.212  2004/10/09 22:26:18  scott
0401 % iv interp. value output, then output grid too -sm
0402 %
0403 % Revision 1.211  2004/10/08 21:34:25  scott
0404 % same -sm
0405 %
0406 % Revision 1.210  2004/10/08 21:32:09  scott
0407 % help message clarification on outputs -sm
0408 %
0409 % Revision 1.209  2004/10/07 15:55:15  scott
0410 % made Values==[] work with plotchans  -sm
0411 %
0412 % Revision 1.208  2004/09/29 15:44:46  scott
0413 % added 'plotchans' option. upgraded 'plotgrid' (still unimplemented) -sm
0414 %
0415 % Revision 1.207  2004/09/29 01:04:22  scott
0416 % created input 'plotgrid' - plotting not yet implemented -sm
0417 %
0418 % Revision 1.206  2004/09/10 00:53:08  hilit
0419 % converted input arguments to text() to double
0420 %
0421 % Revision 1.205  2004/07/07 22:21:30  arno
0422 % debug shrink
0423 %
0424 % Revision 1.204  2004/06/10 19:11:53  arno
0425 % remove debug msg
0426 %
0427 % Revision 1.203  2004/05/14 23:41:09  arno
0428 % allowing negative shrink
0429 %
0430 % Revision 1.202  2004/05/14 23:29:32  arno
0431 % fixing toggle name/number
0432 %
0433 % Revision 1.201  2004/05/10 15:14:34  scott
0434 % more flexible labels/numbers/points argument reading; defined ELECTRODE_HEIGHT
0435 %
0436 % Revision 1.200  2004/05/07 15:12:51  scott
0437 % removed textax, instead plot3() electrode labels/pts/numbers above the rest with plot3() -sm
0438 %
0439 % Revision 1.199  2004/05/07 04:35:10  scott
0440 % superimpose textax again - making both axes square
0441 %
0442 % Revision 1.198  2004/05/05 21:57:23  hilit
0443 % removed text from the previous log message
0444 %
0445 % Revision 1.197  2004/05/05 20:56:20  hilit
0446 % change the defult setting of dipnorm to 'on'.
0447 %
0448 % Revision 1.197  2004/05/05 13:55:00  hilit
0449 % Set the defult option of dipnorm to 'on'
0450 %
0451 % Revision 1.196  2004/05/05 20:36:04  scott
0452 % DIPOLE scaling
0453 %
0454 % Revision 1.195  2004/05/05 20:21:02  scott
0455 % *** empty log message ***
0456 %
0457 % Revision 1.194  2004/04/29 18:58:48  scott
0458 % removed new axes - scaling problem. Toggling pts|numbers doesnt work inside head cartoon.
0459 %
0460 % Revision 1.193  2004/04/29 18:36:46  scott
0461 % test
0462 %
0463 % Revision 1.192  2004/04/29 18:23:03  scott
0464 % make overplot axis limits the same as topoplot limits
0465 %
0466 % Revision 1.191  2004/04/28 18:19:06  scott
0467 % put labels/numbers on another axes so that clicking numbers<->labels
0468 % will work inside the head cartoon patch
0469 %
0470 % Revision 1.190  2004/04/28 17:00:42  scott
0471 % no blanking ring when style is 'blank'
0472 %
0473 % Revision 1.189  2004/04/01 17:10:46  scott
0474 % converted 'conv' interpolation to polar
0475 %
0476 % Revision 1.188  2004/03/31 18:23:15  scott
0477 % debug 'conv' mode - plot ears and nose above map surface to avoid masking by 'conv'
0478 %
0479 % Revision 1.187  2004/03/31 18:06:53  scott
0480 % adding 'conv' mode for plotting convex hull; corrected shrink in 'interp' mode
0481 %
0482 % Revision 1.186  2004/03/31 05:15:05  scott
0483 % *** empty log message ***
0484 %
0485 % Revision 1.185  2004/03/31 05:06:27  scott
0486 % implementing 'conv' (undocumented)
0487 %
0488 % Revision 1.184  2004/03/31 03:19:02  scott
0489 % adjust ear lines
0490 %
0491 % Revision 1.183  2004/03/31 02:53:35  scott
0492 % made blanking ring and head filled rings; made default electrodes 'off' iff chans>64; made contour color
0493 % dark grey; adjusted nose and ear shapes
0494 %
0495 % Revision 1.182  2004/03/31 02:08:07  scott
0496 % *** empty log message ***
0497 %
0498 % Revision 1.181  2004/03/30 18:48:21  scott
0499 % same
0500 %
0501 % Revision 1.180  2004/03/30 18:29:08  scott
0502 % testing fill ring
0503 %
0504 % Revision 1.179  2004/03/30 17:38:15  scott
0505 % plot ring patch instead of blanking circle
0506 %
0507 % Revision 1.178  2004/03/25 22:30:13  arno
0508 % same thing
0509 %
0510 % Revision 1.177  2004/03/25 22:26:45  arno
0511 % same thing
0512 %
0513 % Revision 1.176  2004/03/25 22:24:41  arno
0514 % fixing shrinkfactor bug
0515 %
0516 % Revision 1.175  2004/03/24 16:35:25  scott
0517 % added 'cricgrid' plotting detail argument
0518 %
0519 % Revision 1.174  2004/03/23 19:19:34  scott
0520 % made 'electrodes' default 'off'
0521 %
0522 % Revision 1.173  2004/03/23 19:18:32  scott
0523 % default: plotrad >= 0.5
0524 %
0525 % Revision 1.172  2004/03/23 15:20:39  scott
0526 % made only 2 outputs
0527 %
0528 % Revision 1.171  2004/03/23 00:40:06  scott
0529 % clarifying handling of un-located channels
0530 %
0531 % Revision 1.170  2004/03/22 17:57:21  scott
0532 % added arg 'intrad' - separated interpolation and plotting areas
0533 % Now, by default, interpolates over all the (radius<=1) electrodes.
0534 % Added 'intsquare' option - interpolated values in electrodes in the entire
0535 % interpolation square, not just the (plotting) disk. Can give more accurate
0536 % interpolation at edges of the plotting disk i.e. interpolation instead of
0537 % extrapolation), if there are additional channel locations beyond the plotting area
0538 %
0539 % Revision 1.169  2004/03/22 03:25:41  scott
0540 % re-implmenting shrink options
0541 %
0542 % Revision 1.168  2004/03/21 19:19:18  scott
0543 % help message
0544 %
0545 % Revision 1.167  2004/03/21 18:02:08  scott
0546 % debugged deprecated 'shrink' mode code
0547 %
0548 % Revision 1.166  2004/03/21 17:31:44  scott
0549 % nothing
0550 %
0551 % Revision 1.165  2004/03/21 17:25:39  scott
0552 % corrected dipole plotting
0553 %
0554 % Revision 1.164  2004/03/21 16:52:37  scott
0555 % debugged plotrad, headrad plot size setting
0556 %
0557 % Revision 1.163  2004/03/20 18:20:14  scott
0558 % created 'headrad' (removed 'forcehead'). Now uses only 'plotrad' and 'headrad'
0559 % to set plotting scales. 'shrink' mode disabled temporarily
0560 %
0561 % Revision 1.162  2004/03/19 21:57:58  scott
0562 % do not plot channels with arc_length > 1
0563 %
0564 % Revision 1.161  2004/03/19 19:47:13  arno
0565 % remove str2num
0566 %
0567 % Revision 1.160  2004/03/19 19:05:26  scott
0568 % read string plotrad from channel locations structure
0569 %
0570 % Revision 1.159  2004/03/19 17:46:19  scott
0571 % added 'forcehead'; changed 'pointnumbers' and 'pointlabels' to 'ptnumbers', 'ptlabels'
0572 % but kept backwards compatibility. Allowed marking of multiple channel locations
0573 % without requiring an explicit 'style','blank'. Allowed [] data -> plot channel
0574 % locations. Improved help message and 'example' text. Switched order of plotting
0575 % of head border, electrodes and head cartoon. Made head cartoon not appear by
0576 % default when plotrad<0.5 or 'shrink' is severe (but see 'forcehead'). -sm
0577 %
0578 % Revision 1.158  2004/03/19 02:33:40  scott
0579 % plotting head, ears and/or skirt as appropriate from plotrad and shrink args
0580 %
0581 % Revision 1.157  2004/03/19 01:49:07  scott
0582 % plotrad
0583 %
0584 % Revision 1.156  2004/03/19 00:30:08  scott
0585 % plotrad minmax
0586 %
0587 % Revision 1.155  2004/03/18 17:05:20  arno
0588 % fixed plotrad
0589 %
0590 % Revision 1.154  2004/03/18 16:36:53  arno
0591 % debug shrink and plotrad
0592 %
0593 % Revision 1.153  2004/03/18 16:22:12  arno
0594 % debug shrink
0595 %
0596 % Revision 1.152  2004/03/18 01:47:24  scott
0597 % debug
0598 %
0599 % Revision 1.151  2004/03/18 01:44:28  scott
0600 % 'plotrad' arg and help message re skirt
0601 %
0602 % Revision 1.150  2004/03/18 01:26:33  arno
0603 % plotrad
0604 %
0605 % Revision 1.149  2004/03/18 00:29:07  arno
0606 % debug skirt option
0607 %
0608 % Revision 1.148  2004/03/18 00:18:09  arno
0609 % skirt option
0610 %
0611 % Revision 1.147  2004/02/25 15:29:39  scott
0612 % dont plot border if shrinkfac < .01
0613 %
0614 % Revision 1.146  2004/02/25 15:25:07  scott
0615 % adjust border of 'skirt'
0616 %
0617 % Revision 1.145  2004/02/25 15:19:38  scott
0618 % not allowing shrink to be negative
0619 %
0620 % Revision 1.144  2004/02/23 16:55:51  scott
0621 % don't let ears go outside axes if shrink is 'skirt' but shrink factor is 0 or small
0622 %
0623 % Revision 1.143  2004/02/19 15:56:28  scott
0624 % plot dipole(s) last
0625 %
0626 % Revision 1.142  2004/02/19 15:49:58  scott
0627 % plot dipoles inside head in 'skirt' mode
0628 %
0629 % Revision 1.141  2004/02/18 01:16:53  scott
0630 % help message adjust
0631 %
0632 % Revision 1.140  2004/02/18 01:02:58  scott
0633 % 'dipole' help message. Adaptive AXHEADFAC.
0634 %
0635 % Revision 1.139  2004/02/17 22:44:54  arno
0636 % now processing DIPFIT structure and fixed normalization bug
0637 %
0638 % Revision 1.138  2004/02/17 18:16:35  scott
0639 % adjust EMARKERSIZE
0640 %
0641 % Revision 1.137  2004/02/17 18:11:36  scott
0642 % fixed 'skirt'&'fill' problem. Also, made heads bigger
0643 %
0644 % Revision 1.136  2004/02/17 16:58:24  scott
0645 % change color of outer 'shrink' mode ring to almost white, to avoid print bug
0646 %
0647 % Revision 1.135  2004/02/17 03:14:44  scott
0648 % expand skirt border radius
0649 %
0650 % Revision 1.134  2004/02/15 21:30:01  scott
0651 % same
0652 %
0653 % Revision 1.133  2004/02/15 21:17:07  scott
0654 % omit QUAD_SKIRT option - not ready !
0655 %
0656 % Revision 1.132  2004/02/15 21:02:13  scott
0657 % same
0658 % Revision 1.96  2004/02/15 19:41:48  scott
0659 % skirt with wedges
0660 %
0661 % Revision 1.95  2004/02/15 17:35:49  scott
0662 % added 'style','skirt'
0663 %
0664 % Revision 1.72  2004/02/15 15:58:33  scott
0665 % formatting, try 'shrink','skirt' ...
0666 %
0667 % Revision 1.71  2004/01/20 04:25:05  scott
0668 % help msg edit
0669 % .,
0670 %
0671 % Revision 1.70  2003/12/17 15:49:45  arno
0672 % debug chan with no coordinates
0673 %
0674 % Revision 1.69  2003/12/17 01:25:37  arno
0675 % debug plot electrode subset
0676 %
0677 % Revision 1.68  2003/12/17 00:57:17  arno
0678 % subset of electrodes
0679 %
0680 % Revision 1.67  2003/11/29 23:34:00  scott
0681 % help msg
0682 %
0683 % Revision 1.66  2003/11/06 16:31:18  arno
0684 % changing dipnorm
0685 %
0686 % Revision 1.65  2003/11/06 02:04:41  arno
0687 % correct orientation
0688 %
0689 % Revision 1.64  2003/11/06 01:40:31  arno
0690 % diporient
0691 %
0692 % Revision 1.63  2003/11/06 01:00:57  arno
0693 % adjusting corrdinates
0694 % for dipole
0695 %
0696 % Revision 1.62  2003/11/05 20:35:21  arno
0697 % dipole options
0698 %
0699 % Revision 1.61  2003/11/05 19:44:32  arno
0700 % header text
0701 %
0702 % Revision 1.60  2003/08/08 17:36:12  arno
0703 % shrink factor overwrite problem fixed
0704 %
0705 % Revision 1.59  2003/08/08 17:34:41  arno
0706 % -cos -> cos
0707 %
0708 % Revision 1.58  2003/08/07 20:49:12  arno
0709 % option 'masksurf' to speed up display
0710 %
0711 % Revision 1.57  2003/08/07 16:02:35  scott
0712 % typo
0713 %
0714 % Revision 1.56  2003/08/07 16:01:49  scott
0715 % debug
0716 %
0717 % Revision 1.55  2003/08/07 15:56:54  scott
0718 % debug
0719 %
0720 % Revision 1.54  2003/08/07 15:54:49  scott
0721 % debug last
0722 %
0723 % Revision 1.53  2003/08/07 15:51:05  scott
0724 % added 'noplot' option to return interpolated channel value
0725 %
0726 % Revision 1.52  2003/07/18 01:34:07  scott
0727 % text placement
0728 %
0729 % Revision 1.51  2003/07/18 01:33:19  scott
0730 % text placement
0731 %
0732 % Revision 1.50  2003/07/18 01:31:49  scott
0733 % debug
0734 %
0735 % Revision 1.49  2003/07/18 01:27:17  scott
0736 % debug
0737 %
0738 % Revision 1.48  2003/07/18 01:26:05  scott
0739 % debug
0740 %
0741 % Revision 1.47  2003/07/18 01:18:12  scott
0742 % debug last
0743 %
0744 % Revision 1.46  2003/07/18 01:17:34  scott
0745 % formatting, debug axes size message
0746 %
0747 % Revision 1.45  2003/07/17 23:42:32  scott
0748 % nothing
0749 %
0750 % Revision 1.44  2003/07/17 23:13:03  scott
0751 % rm debug message
0752 %
0753 % Revision 1.43  2003/07/16 16:29:46  arno
0754 % replacing with topoplottest - added image output, gridscale arg
0755 %
0756 % Revision 1.41  2003/07/15 23:55:40  arno
0757 % retreiving version 1.28
0758 %
0759 % Revision 1.28  2003/06/27 18:53:04  arno
0760 % header msg
0761 %
0762 % Revision 1.27  2003/05/12 22:27:44  arno
0763 % debug verbose
0764 %
0765 % Revision 1.26  2003/05/12 22:23:38  arno
0766 % adding verbose option
0767 %
0768 % Revision 1.25  2002/11/27 01:23:53  arno
0769 % change warning message
0770 %
0771 % Revision 1.24  2002/11/12 23:06:48  arno
0772 % still debugging last insert
0773 %
0774 % Revision 1.23  2002/11/12 22:19:01  arno
0775 % typo
0776 %
0777 % Revision 1.22  2002/11/12 21:43:51  scott
0778 % tmpelocs -> tmpeloc
0779 %
0780 % Revision 1.21  2002/11/12 19:33:24  arno
0781 % remove last channel of eloc structure if necessary (common ref)
0782 %
0783 % Revision 1.20  2002/11/01 03:50:08  erik
0784 % same
0785 %
0786 % Revision 1.19  2002/11/01 03:47:40  erik
0787 % added test for locs_file string to readlocs call
0788 %
0789 % Revision 1.18  2002/10/31 22:51:25  luca
0790 % now also plotting n < nchans single channels
0791 %
0792 % Revision 1.17  2002/10/30 18:50:37  arno
0793 % debugging dipole
0794 %
0795 % Revision 1.16  2002/10/30 16:41:21  arno
0796 % adding the dipole option
0797 %
0798 % Revision 1.15  2002/10/26 20:09:35  arno
0799 % error typo
0800 %
0801 % Revision 1.14  2002/10/14 00:40:44  arno
0802 % *** empty log message ***
0803 %
0804 % Revision 1.13  2002/09/23 18:09:11  arno
0805 % fixing single channel plotting
0806 %
0807 % Revision 1.12  2002/08/13 17:45:58  arno
0808 % undo last change
0809 %
0810 % Revision 1.11  2002/08/13 17:44:37  arno
0811 % remove color setting
0812 %
0813 % Revision 1.10  2002/08/12 01:34:53  arno
0814 % color
0815 %
0816 % Revision 1.9  2002/08/11 22:31:20  arno
0817 % color
0818 %
0819 % Revision 1.8  2002/05/01 18:49:20  arno
0820 % modifying default shrink
0821 %
0822 % Revision 1.7  2002/05/01 02:40:10  arno
0823 % typo
0824 %
0825 % Revision 1.6  2002/04/24 17:30:47  arno
0826 % auto shrink
0827 %
0828 % Revision 1.5  2002/04/24 17:07:28  arno
0829 % debugging error message problem
0830 %
0831 % Revision 1.4  2002/04/17 18:40:23  arno
0832 % display real electrode number
0833 %
0834 % Revision 1.3  2002/04/06 03:47:44  arno
0835 % adding emarkersize1chan input
0836 %
0837 % Revision 1.2  2002/04/06 03:37:24  arno
0838 % adding single channel vector input
0839 %
0840 % Revision 1.1  2002/04/05 17:36:45  jorn
0841 % Initial revision
0842 %
0843 
0844 % Topoplot Version 2.1
0845 % Early development history:
0846 % Begun by Andy Spydell and Scott Makeig, NHRC,  7-23-96
0847 % 8-96 Revised by Colin Humphries, CNL / Salk Institute, La Jolla CA
0848 %   -changed surf command to imagesc (faster)
0849 %   -can now handle arbitrary scaling of electrode distances
0850 %   -can now handle non integer angles in chan_locs
0851 % 4-4-97 Revised again by Colin Humphries, reformatted by SM
0852 %   -added parameters
0853 %   -changed chan_locs format
0854 % 2-26-98 Revised by Colin
0855 %   -changed image back to surface command
0856 %   -added fill and blank styles
0857 %   -removed extra background colormap entry (now use any colormap)
0858 %   -added parameters for electrode colors and labels
0859 %   -now each topoplot axes use the caxis command again.
0860 %   -removed OUTPUT parameter
0861 % 3-11-98 changed default emarkersize, improve help msg -sm
0862 % 5-24-01 made default emarkersize vary with number of channels -sm
0863 % 01-25-02 reformated help & license, added link -ad
0864 % 03-15-02 added readlocs and the use of eloc input structure -ad
0865 % 03-25-02 added 'labelpoint' options and allow Values=[] -ad &sm
0866 % 03-25-02 added details to "Unknown parameter" warning -sm & ad
0867 % 01-25-15 added a conditional that adjusts EMARKER2CHANS to reflect
0868 % channels that are not visualized (e.g., because they have empty
0869 % coordinates in the loc_file) DG
0870 % 06-25: mark1chans and mark2chans flipped to be row vectors if they are
0871 % column vectors DG
0872 
0873 function [handle,Zi,grid,Xi,Yi] = topoplotMK(Values,loc_file,varargin)
0874 
0875 %
0876 %%%%%%%%%%%%%%%%%%%%%%%% Set defaults %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0877 %
0878 icadefs                 % read defaults MAXTOPOPLOTCHANS and DEFAULT_ELOC and BACKCOLOR
0879 if ~exist('BACKCOLOR')  % if icadefs.m does not define BACKCOLOR
0880     BACKCOLOR = [.93 .96 1];  % EEGLAB standard
0881 end
0882 whitebk = 'off';  % by default, make gridplot background color = EEGLAB screen background color
0883 
0884 plotgrid = 'off';
0885 plotchans = [];
0886 noplot  = 'off';
0887 handle = [];
0888 Zi = [];
0889 chanval = NaN;
0890 rmax = 0.5;             % actual head radius - Don't change this!
0891 INTERPLIMITS = 'head';  % head, electrodes
0892 INTSQUARE = 'on';       % default, interpolate electrodes located though the whole square containing
0893 % the plotting disk
0894 default_intrad = 1;     % indicator for (no) specified intrad
0895 MAPLIMITS = 'absmax';   % absmax, maxmin, [values]
0896 GRID_SCALE = 67;        % plot map on a 67X67 grid
0897 CIRCGRID   = 201;       % number of angles to use in drawing circles
0898 AXHEADFAC = 1.3;        % head to axes scaling factor
0899 CONTOURNUM = 6;         % number of contour levels to plot
0900 STYLE = 'both';         % default 'style': both,straight,fill,contour,blank
0901 HEADCOLOR = [0 0 0];    % default head color (black)
0902 CCOLOR = [0.2 0.2 0.2]; % default contour color
0903 ELECTRODES = [];        % default 'electrodes': on|off|label - set below
0904 MAXDEFAULTSHOWLOCS = 200;% if more channels than this, don't show electrode locations by default
0905 EMARKER = '.';          % mark electrode locations with small disks
0906 ECOLOR = [0 0 0];       % default electrode color = black
0907 EMARKERSIZE = [];       % default depends on number of electrodes, set in code
0908 EMARKERLINEWIDTH = 1;   % default edge linewidth for emarkers
0909 EMARKERSIZE1CHAN = 40;  % default selected channel location marker size
0910 EMARKERCOLOR1CHAN = 'red'; % selected channel location marker color
0911 EMARKER2CHANS = [];      % mark subset of electrode locations with small disks
0912 EMARKER2 = 'o';          % mark subset of electrode locations with small disks
0913 EMARKER2COLOR = 'r';     % mark subset of electrode locations with small disks
0914 EMARKERSIZE2 = 10;      % default selected channel location marker size
0915 EMARKER2LINEWIDTH = 1;
0916 EFSIZE = get(0,'DefaultAxesFontSize'); % use current default fontsize for electrode labels
0917 HLINEWIDTH = 1.7;         % default linewidth for head, nose, ears
0918 BLANKINGRINGWIDTH = .035;% width of the blanking ring
0919 HEADRINGWIDTH    = .007;% width of the cartoon head ring
0920 SHADING = 'flat';       % default 'shading': flat|interp
0921 shrinkfactor = [];      % shrink mode (dprecated)
0922 intrad       = [];      % default interpolation square is to outermost electrode (<=1.0)
0923 plotrad      = [];      % plotting radius ([] = auto, based on outermost channel location)
0924 headrad      = [];      % default plotting radius for cartoon head is 0.5
0925 squeezefac = 1.0;
0926 MINPLOTRAD = 0.15;      % can't make a topoplot with smaller plotrad (contours fail)
0927 VERBOSE = 'off';
0928 MASKSURF = 'off';
0929 CONVHULL = 'off';       % dont mask outside the electrodes convex hull
0930 DRAWAXIS = 'off';
0931 CHOOSECHANTYPE = 0;
0932 ContourVals = Values;
0933 PMASKFLAG   = 0;
0934 plain_blank=0; % If 1, when plotting a blank topography (i.e., no data, just locations),
0935 % don't fill in disks with a red spot and do add on auto-text (e.g.,
0936 %'channel locations title') Differs from EEGLAB version and added to
0937 % make MATLABmk function gui_erp.m work. -DG
0938 
0939 %%%%%% Dipole defaults %%%%%%%%%%%%
0940 DIPOLE  = [];
0941 DIPNORM   = 'on';
0942 DIPSPHERE = 85;
0943 DIPLEN    = 1;
0944 DIPSCALE  = 1;
0945 DIPORIENT  = 1;
0946 DIPCOLOR  = [0 0 0];
0947 NOSEDIR   = '+X';
0948 CHANINFO  = [];
0949 
0950 
0951 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0952 
0953 %
0954 %%%%%%%%%%%%%%%%%%%%%%% Handle arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0955 %
0956 if nargin< 1
0957     help topoplot;
0958     return
0959 end
0960 
0961 % calling topoplot from Fieldtrip
0962 % -------------------------------
0963 fieldtrip = 0;
0964 if nargin < 2, loc_file = []; end;
0965 if isstruct(Values) | ~isstruct(loc_file), fieldtrip == 1; end;
0966 if isstr(loc_file), if exist(loc_file) ~= 2, fieldtrip == 1; end; end;
0967 if fieldtrip
0968     disp('Calling topoplot from Fieldtrip');
0969     dir1 = which('topoplot');           dir1 = fileparts(dir1);
0970     dir2 = which('electrodenormalize'); dir2 = fileparts(dir2);
0971     addpath(dir2);
0972     try,
0973         topoplot(Values, loc_file, varargin{:});
0974     catch,
0975     end;
0976     addpath(dir1);
0977     return;
0978 end;
0979 
0980 nargs = nargin;
0981 if nargs == 1
0982     if isstr(Values)
0983         if any(strcmp(lower(Values),{'example','demo'}))
0984             fprintf(['This is an example of an electrode location file,\n',...
0985                 'an ascii file consisting of the following four columns:\n',...
0986                 ' channel_number degrees arc_length channel_name\n\n',...
0987                 'Example:\n',...
0988                 ' 1               -18    .352       Fp1 \n',...
0989                 ' 2                18    .352       Fp2 \n',...
0990                 ' 5               -90    .181       C3  \n',...
0991                 ' 6                90    .181       C4  \n',...
0992                 ' 7               -90    .500       A1  \n',...
0993                 ' 8                90    .500       A2  \n',...
0994                 ' 9              -142    .231       P3  \n',...
0995                 '10               142    .231       P4  \n',...
0996                 '11                 0    .181       Fz  \n',...
0997                 '12                 0    0          Cz  \n',...
0998                 '13               180    .181       Pz  \n\n',...
0999                 ...
1000                 'In topoplot() coordinates, 0 deg. points to the nose, positive\n',...
1001                 'angles point to the right hemisphere, and negative to the left.\n',...
1002                 'The model head sphere has a circumference of 2; the vertex\n',...
1003                 '(Cz) has arc_length 0. Locations with arc_length > 0.5 are below\n',...
1004                 'head center and are plotted outside the head cartoon.\n'....
1005                 'Option plotrad controls how much of this lower-head "skirt" is shown.\n',...
1006                 'Option headrad controls if and where the cartoon head will be drawn.\n',...
1007                 'Option intrad controls how many channels will be included in the interpolation.\n',...
1008                 ])
1009             return
1010         end
1011     end
1012 end
1013 if nargs < 2
1014     loc_file = DEFAULT_ELOC;
1015     if ~exist(loc_file)
1016         fprintf('default locations file "%s" not found - specify chan_locs in topoplot() call.\n',loc_file)
1017         error(' ')
1018     end
1019 end
1020 if isempty(loc_file)
1021     loc_file = 0;
1022 end
1023 if isnumeric(loc_file) & loc_file == 0
1024     loc_file = DEFAULT_ELOC;
1025 end
1026 
1027 if nargs > 2
1028     if ~(round(nargs/2) == nargs/2)
1029         error('Odd number of input arguments??')
1030     end
1031     for i = 1:2:length(varargin)
1032         Param = varargin{i};
1033         Value = varargin{i+1};
1034         if ~isstr(Param)
1035             error('Flag arguments must be strings')
1036         end
1037         Param = lower(Param);
1038         switch Param
1039             case 'conv'
1040                 CONVHULL = lower(Value);
1041                 if ~strcmp(CONVHULL,'on') && ~strcmp(CONVHULL,'off')
1042                     error('Value of ''conv'' must be ''on'' or ''off''.');
1043                 end
1044             case 'colormap'
1045                 if size(Value,2)~=3
1046                     error('Colormap must be a n x 3 matrix')
1047                 end
1048                 colormap(Value)
1049             case 'intsquare'
1050                 INTSQUARE = lower(Value);
1051                 if ~strcmp(INTSQUARE,'on') && ~strcmp(INTSQUARE,'off')
1052                     error('Value of ''intsquare'' must be ''on'' or ''off''.');
1053                 end
1054             case {'interplimits','headlimits'}
1055                 if ~isstr(Value)
1056                     error('''interplimits'' value must be a string')
1057                 end
1058                 Value = lower(Value);
1059                 if ~strcmp(Value,'electrodes') && ~strcmp(Value,'head')
1060                     error('Incorrect value for interplimits')
1061                 end
1062                 INTERPLIMITS = Value;
1063             case 'verbose'
1064                 VERBOSE = Value;
1065             case 'nosedir'
1066                 NOSEDIR = Value;
1067                 if isempty(strmatch(lower(NOSEDIR), { '+x', '-x', '+y', '-y' }))
1068                     error('Invalid nose direction');
1069                 end;
1070             case 'chaninfo'
1071                 CHANINFO = Value;
1072                 if isfield(CHANINFO, 'nosedir'), NOSEDIR      = CHANINFO.nosedir; end;
1073                 if isfield(CHANINFO, 'shrink' ), shrinkfactor = CHANINFO.shrink;  end;
1074                 if isfield(CHANINFO, 'plotrad') && isempty(plotrad), plotrad = CHANINFO.plotrad; end;
1075                 if isfield(CHANINFO, 'chantype')
1076                     chantype = CHANINFO.chantype;
1077                     if ischar(chantype), chantype = cellstr(chantype); end
1078                     CHOOSECHANTYPE = 1;
1079                 end
1080             case 'chantype'
1081                 chantype = Value;
1082                 CHOOSECHANTYPE = 1;
1083                 if ischar(chantype), chantype = cellstr(chantype); end
1084                 if ~iscell(chantype), error('chantype must be cell array. e.g. {''EEG'', ''EOG''}'); end
1085             case 'drawaxis'
1086                 DRAWAXIS = Value;
1087             case 'maplimits'
1088                 MAPLIMITS = Value;
1089             case 'masksurf'
1090                 MASKSURF = Value;
1091             case 'circgrid'
1092                 CIRCGRID = Value;
1093                 if isstr(CIRCGRID) | CIRCGRID<100
1094                     error('''circgrid'' value must be an int > 100');
1095                 end
1096             case 'style'
1097                 STYLE = lower(Value);
1098             case 'numcontour'
1099                 CONTOURNUM = Value;
1100             case 'electrodes'
1101                 ELECTRODES = lower(Value);
1102                 if strcmpi(ELECTRODES,'pointlabels') | strcmpi(ELECTRODES,'ptslabels') ...
1103                         | strcmpi(ELECTRODES,'labelspts') | strcmpi(ELECTRODES,'ptlabels') ...
1104                         | strcmpi(ELECTRODES,'labelpts')
1105                     ELECTRODES = 'labelpoint'; % backwards compatability
1106                 elseif strcmpi(ELECTRODES,'pointnumbers') | strcmpi(ELECTRODES,'ptsnumbers') ...
1107                         | strcmpi(ELECTRODES,'numberspts') | strcmpi(ELECTRODES,'ptnumbers') ...
1108                         | strcmpi(ELECTRODES,'numberpts')  | strcmpi(ELECTRODES,'ptsnums')  ...
1109                         | strcmpi(ELECTRODES,'numspts')
1110                     ELECTRODES = 'numpoint'; % backwards compatability
1111                 elseif strcmpi(ELECTRODES,'nums')
1112                     ELECTRODES = 'numbers'; % backwards compatability
1113                 elseif strcmpi(ELECTRODES,'pts')
1114                     ELECTRODES = 'on'; % backwards compatability
1115                 elseif ~strcmp(ELECTRODES,'off') ...
1116                         & ~strcmpi(ELECTRODES,'on') ...
1117                         & ~strcmp(ELECTRODES,'labels') ...
1118                         & ~strcmpi(ELECTRODES,'numbers') ...
1119                         & ~strcmpi(ELECTRODES,'labelpoint') ...
1120                         & ~strcmpi(ELECTRODES,'numpoint')
1121                     error('Unknown value for keyword ''electrodes''');
1122                 end
1123             case 'dipole'
1124                 DIPOLE = Value;
1125             case 'dipsphere'
1126                 DIPSPHERE = Value;
1127             case 'dipnorm'
1128                 DIPNORM = Value;
1129             case 'diplen'
1130                 DIPLEN = Value;
1131             case 'dipscale'
1132                 DIPSCALE = Value;
1133             case 'contourvals'
1134                 ContourVals = Value;
1135             case 'pmask'
1136                 ContourVals = Value;
1137                 PMASKFLAG   = 1;
1138             case 'diporient'
1139                 DIPORIENT = Value;
1140             case 'dipcolor'
1141                 DIPCOLOR = Value;
1142             case 'emarker'
1143                 if ischar(Value)
1144                     EMARKER = Value;
1145                 elseif ~iscell(Value) | length(Value) > 4
1146                     error('''emarker'' argument must be a cell array {marker color size linewidth}')
1147                 else
1148                     EMARKER = Value{1};
1149                 end
1150                 if length(Value) > 1
1151                     ECOLOR = Value{2};
1152                 end
1153                 if length(Value) > 2
1154                     EMARKERSIZE2 = Value{3};
1155                 end
1156                 if length(Value) > 3
1157                     EMARKERLINEWIDTH = Value{4};
1158                 end
1159             case 'emarker2'
1160                 if ~iscell(Value) | length(Value) > 5
1161                     error('''emarker2'' argument must be a cell array {chans marker color size linewidth}')
1162                 end
1163                 EMARKER2CHANS = abs(Value{1}); % ignore channels < 0
1164                 if length(Value) > 1
1165                     EMARKER2 = Value{2};
1166                 end
1167                 if length(Value) > 2
1168                     EMARKER2COLOR = Value{3};
1169                 end
1170                 if length(Value) > 3
1171                     EMARKERSIZE2 = Value{4};
1172                 end
1173                 if length(Value) > 4
1174                     EMARKER2LINEWIDTH = Value{5};
1175                 end
1176             case 'shrink'
1177                 shrinkfactor = Value;
1178             case 'plain_blank'
1179                 plain_blank = Value;
1180             case 'intrad'
1181                 intrad = Value;
1182                 if isstr(intrad) | (intrad < MINPLOTRAD | intrad > 1)
1183                     error('intrad argument should be a number between 0.15 and 1.0');
1184                 end
1185             case 'plotrad'
1186                 plotrad = Value;
1187                 if isstr(plotrad) | (plotrad < MINPLOTRAD | plotrad > 1)
1188                     error('plotrad argument should be a number between 0.15 and 1.0');
1189                 end
1190             case 'headrad'
1191                 headrad = Value;
1192                 if isstr(headrad) & ( strcmpi(headrad,'off') | strcmpi(headrad,'none') )
1193                     headrad = 0;       % undocumented 'no head' alternatives
1194                 end
1195                 if isempty(headrad) % [] -> none also
1196                     headrad = 0;
1197                 end
1198                 if ~isstr(headrad)
1199                     if ~(headrad==0) & (headrad < MINPLOTRAD | headrad>1)
1200                         error('bad value for headrad');
1201                     end
1202                 elseif  ~strcmpi(headrad,'rim')
1203                     error('bad value for headrad');
1204                 end
1205             case {'headcolor','hcolor'}
1206                 HEADCOLOR = Value;
1207             case {'contourcolor','ccolor'}
1208                 CCOLOR = Value;
1209             case {'electcolor','ecolor'}
1210                 ECOLOR = Value;
1211             case {'emarkersize','emsize'}
1212                 EMARKERSIZE = Value;
1213             case {'emarkersize1chan','emarkersizemark'}
1214                 EMARKERSIZE1CHAN= Value;
1215             case {'efontsize','efsize'}
1216                 EFSIZE = Value;
1217             case 'shading'
1218                 SHADING = lower(Value);
1219                 if ~any(strcmp(SHADING,{'flat','interp'}))
1220                     error('Invalid shading parameter')
1221                 end
1222             case 'noplot'
1223                 noplot = Value;
1224                 if ~isstr(noplot)
1225                     if length(noplot) ~= 2
1226                         error('''noplot'' location should be [radius, angle]')
1227                     else
1228                         chanrad = noplot(1);
1229                         chantheta = noplot(2);
1230                         noplot = 'on';
1231                     end
1232                 end
1233             case 'gridscale'
1234                 GRID_SCALE = Value;
1235                 if isstr(GRID_SCALE) | GRID_SCALE ~= round(GRID_SCALE) | GRID_SCALE < 32
1236                     error('''gridscale'' value must be integer > 32.');
1237                 end
1238             case {'plotgrid','gridplot'}
1239                 plotgrid = 'on';
1240                 gridchans = Value;
1241             case 'plotchans'
1242                 plotchans = Value(:);
1243                 if find(plotchans<=0)
1244                     error('''plotchans'' values must be > 0');
1245                 end
1246                 % if max(abs(plotchans))>max(Values) | max(abs(plotchans))>length(Values) -sm ???
1247             case {'whitebk','whiteback','forprint'}
1248                 whitebk = Value;
1249             otherwise
1250                 error(['Unknown input parameter ''' Param ''' ???'])
1251         end
1252     end
1253 end
1254 if strcmpi(whitebk, 'on')
1255     BACKCOLOR = [ 1 1 1 ];
1256 end;
1257 
1258 cmap = colormap;
1259 cmaplen = size(cmap,1);
1260 
1261 %
1262 %%%%%%%%%%%%%%%%%%%%%%%%%%% test args for plotting an electrode grid %%%%%%%%%%%%%%%%%%%%%%
1263 %
1264 if strcmp(plotgrid,'on')
1265     STYLE = 'grid';
1266     gchans = sort(find(abs(gridchans(:))>0));
1267     
1268     % if setdiff(gchans,unique(gchans))
1269     %      fprintf('topoplot() warning: ''plotgrid'' channel matrix has duplicate channels\n');
1270     % end
1271     
1272     if ~isempty(plotchans)
1273         if intersect(gchans,abs(plotchans))
1274             fprintf('topoplot() warning: ''plotgrid'' and ''plotchans'' have channels in common\n');
1275         end
1276     end
1277 end
1278 
1279 %
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%% misc arg tests %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1281 %
1282 if isempty(ELECTRODES)                     % if electrode labeling not specified
1283     if length(Values) > MAXDEFAULTSHOWLOCS   % if more channels than default max
1284         ELECTRODES = 'off';                    % don't show electrodes
1285     else                                     % else if fewer chans,
1286         ELECTRODES = 'on';                     % do
1287     end
1288 end
1289 
1290 if isempty(Values)
1291     STYLE = 'blank';
1292 end
1293 [r,c] = size(Values);
1294 if r>1 & c>1,
1295     error('input data must be a single vector');
1296 end
1297 Values = Values(:); % make Values a column vector
1298 ContourVals = ContourVals(:); % values for contour
1299 
1300 if ~isempty(intrad) & ~isempty(plotrad) & intrad < plotrad
1301     error('intrad must be >= plotrad');
1302 end
1303 
1304 if ~strcmpi(STYLE,'grid')                     % if not plot grid only
1305     
1306     %
1307     %%%%%%%%%%%%%%%%%%%% Read the channel location information %%%%%%%%%%%%%%%%%%%%%%%%
1308     %
1309     if isstr(loc_file)
1310         [tmpeloc labels Th Rd indices] = readlocs( loc_file,'filetype','loc');
1311     elseif isstruct(loc_file) % a locs struct
1312         [tmpeloc labels Th Rd indices] = readlocs( loc_file );
1313         % Note: Th and Rd correspond to indices channels-with-coordinates only
1314     else
1315         error('loc_file must be a EEG.locs struct or locs filename');
1316     end
1317     Th = pi/180*Th;                              % convert degrees to radians
1318     allchansind = 1:length(Th);
1319     
1320     
1321     %
1322     %%%%%%%%%% if channels-to-mark-only are given in Values vector %%%%%%%%%%%%%%%%%
1323     %
1324     if length(Values) < length(tmpeloc) & strcmpi( STYLE, 'blank') % if Values contains int channel indices to mark
1325         if isempty(plotchans)
1326             if Values ~= abs(round(Values)) | min(abs(Values))< 1  % if not positive integer values
1327                 error('Negative channel indices');
1328             elseif strcmpi(VERBOSE, 'on')
1329                 fprintf('topoplot(): max chan number (%d) in locs > channels in data (%d).\n',...
1330                     max(indices),length(Values));
1331                 fprintf('            Marking the locations of the %d indicated channels.\n', ...
1332                     length(Values));
1333             end
1334             plotchans = Values;
1335             STYLE = 'blank'; % plot channels only, marking the indicated channel number
1336             if strcmpi(ELECTRODES,'off')
1337                 ELECTRODES = 'on';
1338             end
1339         else
1340             error('input ''plotchans'' not allowed when input data are channel numbers');
1341         end
1342     elseif length(Values) > length(tmpeloc)
1343        error('There are more Values than electrodes.'); % Groppe added this Jan 24, 2015 DG
1344     end
1345     
1346     if ~isempty(plotchans)
1347         if max(plotchans) > length(Th)
1348             error('''plotchans'' values must be <= max channel index');
1349         end
1350     end
1351     
1352     %
1353     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% channels to plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1354     %
1355     if ~isempty(plotchans)
1356         plotchans = intersect(plotchans, indices);
1357     end;
1358     if ~isempty(Values) & ~strcmpi( STYLE, 'blank') & isempty(plotchans)
1359         plotchans = indices;
1360     end
1361     if isempty(plotchans) & strcmpi( STYLE, 'blank')
1362         plotchans = indices;
1363     end
1364     % Groppe added the following conditional
1365     if length(Values)>length(plotchans)
1366        %some channels have been removed (e.g., if they did not have coordinates in the locfile)
1367        
1368        % Adjust EMARKER2CHAN indices to reflect missing channels
1369        tempVec=zeros(length(Values),1);
1370        tempVec(EMARKER2CHANS)=1;
1371        EMARKER2CHANS=find(tempVec(plotchans));
1372     end
1373     %
1374     %%%%%%%%%%%%%%%%%%%%%%%%%%% filter for channel type(s), if specified %%%%%%%%%%%%%%%%%%%%%
1375     %
1376     
1377     if CHOOSECHANTYPE,
1378         newplotchans = eeg_chantype(loc_file,chantype);
1379         plotchans = intersect(newplotchans, plotchans);
1380     end
1381     
1382     %
1383     %%%%%%%%%%%%%%%%%%%%%%%%%%% filter channels used for components %%%%%%%%%%%%%%%%%%%%%
1384     %
1385     if isfield(CHANINFO, 'icachansind') & ~isempty(Values) & length(Values) ~= length(tmpeloc)
1386         
1387         % test if ICA component
1388         % ---------------------
1389         if length(CHANINFO.icachansind) == length(Values)
1390             
1391             % if only a subset of channels are to be plotted
1392             % and ICA components also use a subject of channel
1393             % we must find the new indices for these channels
1394             
1395             plotchans = intersect(CHANINFO.icachansind, plotchans);
1396             tmpvals   = zeros(1, length(tmpeloc));
1397             tmpvals(CHANINFO.icachansind) = Values;
1398             Values    = tmpvals;
1399             tmpvals   = zeros(1, length(tmpeloc));
1400             tmpvals(CHANINFO.icachansind) = ContourVals;
1401             ContourVals = tmpvals;
1402             
1403         end;
1404     end;
1405     
1406     %
1407     %%%%%%%%%%%%%%%%%%% last channel is reference? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408     %
1409     if length(tmpeloc) == length(Values) + 1 % remove last channel if necessary
1410         % (common reference channel)
1411         if plotchans(end) == length(tmpeloc)
1412             plotchans(end) = [];
1413         end;
1414         
1415     end;
1416     
1417     %
1418     %%%%%%%%%%%%%%%%%%% remove infinite and NaN values %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419     %
1420     if length(Values) > 1
1421         inds          = union(find(isnan(Values)), find(isinf(Values))); % NaN and Inf values
1422         plotchans     = setdiff(plotchans, inds);
1423     end;
1424     if strcmp(plotgrid,'on')
1425         plotchans = setxor(plotchans,gchans);   % remove grid chans from head plotchans
1426     end
1427     
1428     [x,y]     = pol2cart(Th,Rd);  % transform electrode locations from polar to cartesian coordinates
1429     plotchans = abs(plotchans);   % reverse indicated channel polarities
1430     allchansind = allchansind(plotchans);
1431     Th        = Th(plotchans);
1432     Rd        = Rd(plotchans);
1433     x         = x(plotchans);
1434     y         = y(plotchans);
1435     labels    = labels(plotchans); % remove labels for electrodes without locations
1436     labels    = strvcat(labels); % make a label string matrix
1437     if ~isempty(Values) & length(Values) > 1 & ~strcmpi( STYLE, 'blank')
1438         Values      = Values(plotchans);
1439         ContourVals = ContourVals(plotchans);
1440     end;
1441     
1442     %
1443     %%%%%%%%%%%%%%%%%% Read plotting radius from chanlocs  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444     %
1445     if isempty(plotrad) & isfield(tmpeloc, 'plotrad'),
1446         plotrad = tmpeloc(1).plotrad;
1447         if isstr(plotrad)                        % plotrad shouldn't be a string
1448             plotrad = str2num(plotrad)           % just checking
1449         end
1450         if plotrad < MINPLOTRAD | plotrad > 1.0
1451             fprintf('Bad value (%g) for plotrad.\n',plotrad);
1452             error(' ');
1453         end
1454         if strcmpi(VERBOSE,'on') & ~isempty(plotrad)
1455             fprintf('Plotting radius plotrad (%g) set from EEG.chanlocs.\n',plotrad);
1456         end
1457     end;
1458     if isempty(plotrad)
1459         plotrad = min(1.0,max(Rd)*1.02);            % default: just outside the outermost electrode location
1460         plotrad = max(plotrad,0.5);                 % default: plot out to the 0.5 head boundary
1461     end                                           % don't plot channels with Rd > 1 (below head)
1462     
1463     if isempty(intrad)
1464         default_intrad = 1;     % indicator for (no) specified intrad
1465         intrad = min(1.0,max(Rd)*1.02);             % default: just outside the outermost electrode location
1466     else
1467         default_intrad = 0;                         % indicator for (no) specified intrad
1468         if plotrad > intrad
1469             plotrad = intrad;
1470         end
1471     end                                           % don't interpolate channels with Rd > 1 (below head)
1472     if isstr(plotrad) | plotrad < MINPLOTRAD | plotrad > 1.0
1473         error('plotrad must be between 0.15 and 1.0');
1474     end
1475     
1476     %
1477     %%%%%%%%%%%%%%%%%%%%%%% Set radius of head cartoon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1478     %
1479     if isempty(headrad)  % never set -> defaults
1480         if plotrad >= rmax
1481             headrad = rmax;  % (anatomically correct)
1482         else % if plotrad < rmax
1483             headrad = 0;    % don't plot head
1484             if strcmpi(VERBOSE, 'on')
1485                 fprintf('topoplot(): not plotting cartoon head since plotrad (%5.4g) < 0.5\n',...
1486                     plotrad);
1487             end
1488         end
1489     elseif strcmpi(headrad,'rim') % force plotting at rim of map
1490         headrad = plotrad;
1491     end
1492     
1493     %
1494     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Shrink mode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495     %
1496     if ~isempty(shrinkfactor) | isfield(tmpeloc, 'shrink'),
1497         if isempty(shrinkfactor) & isfield(tmpeloc, 'shrink'),
1498             shrinkfactor = tmpeloc(1).shrink;
1499             if strcmpi(VERBOSE,'on')
1500                 if isstr(shrinkfactor)
1501                     fprintf('Automatically shrinking coordinates to lie above the head perimter.\n');
1502                 else
1503                     fprintf('Automatically shrinking coordinates by %3.2f\n', shrinkfactor);
1504                 end;
1505             end
1506         end;
1507         
1508         if ischar(shrinkfactor)
1509             if strcmpi(shrinkfactor, 'on') || strcmpi(shrinkfactor, 'force') || strcmpi(shrinkfactor, 'auto')
1510                 if abs(headrad-rmax) > 1e-2
1511                     fprintf('     NOTE -> the head cartoon will NOT accurately indicate the actual electrode locations\n');
1512                 end
1513                 if strcmpi(VERBOSE,'on')
1514                     fprintf('     Shrink flag -> plotting cartoon head at plotrad\n');
1515                 end
1516                 headrad = plotrad; % plot head around outer electrodes, no matter if 0.5 or not
1517             end
1518         else % apply shrinkfactor
1519             plotrad = rmax/(1-shrinkfactor);
1520             headrad = plotrad;  % make deprecated 'shrink' mode plot
1521             if strcmpi(VERBOSE,'on')
1522                 fprintf('    shrink  applied.');
1523                 if abs(headrad-rmax) > 1e-2
1524                     fprintf(' Warning: With this "shrink" setting, the cartoon head will NOT be anatomically correct.\n');
1525                 else
1526                     fprintf('\n');
1527                 end
1528             end
1529         end
1530     end; % if shrink
1531     
1532     %
1533     %%%%%%%%%%%%%%%%% Issue warning if headrad ~= rmax  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1534     %
1535     
1536     if headrad ~= 0.5 & strcmpi(VERBOSE, 'on')
1537         fprintf('     NB: Plotting map using ''plotrad'' %-4.3g,',plotrad);
1538         fprintf(    ' ''headrad'' %-4.3g\n',headrad);
1539         fprintf('Warning: The plotting radius of the cartoon head is NOT anatomically correct (0.5).\n')
1540     end
1541     %
1542     %%%%%%%%%%%%%%%%%%%%% Find plotting channels  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1543     %
1544     
1545     pltchans = find(Rd <= plotrad); % plot channels inside plotting circle
1546     
1547     if strcmpi(INTSQUARE,'on') &  ~strcmpi(STYLE,'blank') % interpolate channels in the radius intrad square
1548         intchans = find(x <= intrad & y <= intrad); % interpolate and plot channels inside interpolation square
1549     else
1550         intchans = find(Rd <= intrad); % interpolate channels in the radius intrad circle only
1551     end
1552     
1553     %
1554     %%%%%%%%%%%%%%%%%%%%% Eliminate channels not plotted  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555     %
1556     
1557     allx      = x;
1558     ally      = y;
1559     intchans; % interpolate using only the 'intchans' channels
1560     pltchans; % plot using only indicated 'plotchans' channels
1561     
1562     if length(pltchans) < length(Rd) & strcmpi(VERBOSE, 'on')
1563         fprintf('Interpolating %d and plotting %d of the %d scalp electrodes.\n', ...
1564             length(intchans),length(pltchans),length(Rd));
1565     end;
1566     
1567     
1568     % fprintf('topoplot(): plotting %d channels\n',length(pltchans));
1569     if ~isempty(EMARKER2CHANS)
1570         if strcmpi(STYLE,'blank') & ~plain_blank,
1571             error('emarker2 not defined for style ''blank'' - use marking channel numbers in place of data');
1572         else % mark1chans and mark2chans are subsets of pltchans for markers 1 and 2
1573             [tmp1 mark1chans tmp2] = setxor(pltchans,EMARKER2CHANS);
1574             [tmp3 tmp4 mark2chans] = intersect(EMARKER2CHANS,pltchans);
1575         end
1576     end
1577     
1578     if ~isempty(Values)
1579         if length(Values) == length(Th)  % if as many map Values as channel locs
1580             intValues      = Values(intchans);
1581             intContourVals = ContourVals(intchans);
1582             Values         = Values(pltchans);
1583             ContourVals    = ContourVals(pltchans);
1584         else
1585             if strcmp(STYLE,'blank')    % else if Values holds numbers of channels to mark
1586                 tmpValues=[];
1587                 cc=1;
1588                 for kk=1:length(Values)
1589                     tmpind = find(pltchans == Values(kk));
1590                     if ~isempty(tmpind)
1591                         tmpValues(cc) = tmpind;
1592                         cc=cc+1;
1593                     end;
1594                 end
1595                 Values=tmpValues;     % eliminate the channel indices outside plotting area
1596             end;
1597         end;
1598     end;   % now channel parameters and values all refer to plotting channels only
1599     
1600     allchansind = allchansind(pltchans);
1601     intTh = Th(intchans);           % eliminate channels outside the interpolation area
1602     intRd = Rd(intchans);
1603     intx  = x(intchans);
1604     inty  = y(intchans);
1605     Th    = Th(pltchans);              % eliminate channels outside the plotting area
1606     Rd    = Rd(pltchans);
1607     x     = x(pltchans);
1608     y     = y(pltchans);
1609     
1610     labels= labels(pltchans,:);
1611     %
1612     %%%%%%%%%%%%%%% Squeeze channel locations to <= rmax %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1613     %
1614     
1615     squeezefac = rmax/plotrad;
1616     intRd = intRd*squeezefac; % squeeze electrode arc_lengths towards the vertex
1617     Rd = Rd*squeezefac;       % squeeze electrode arc_lengths towards the vertex
1618     % to plot all inside the head cartoon
1619     intx = intx*squeezefac;
1620     inty = inty*squeezefac;
1621     x    = x*squeezefac;
1622     y    = y*squeezefac;
1623     allx    = allx*squeezefac;
1624     ally    = ally*squeezefac;
1625     % Note: Now outermost channel will be plotted just inside rmax
1626     
1627 else % if strcmpi(STYLE,'grid')
1628     intx = rmax; inty=rmax;
1629 end % if ~strcmpi(STYLE,'grid')
1630 
1631 %
1632 %%%%%%%%%%%%%%%% rotate channels based on chaninfo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1633 %
1634 if strcmpi(lower(NOSEDIR), '+x')
1635     rotate = 0;
1636 else
1637     if strcmpi(lower(NOSEDIR), '+y')
1638         rotate = 3*pi/2;
1639     elseif strcmpi(lower(NOSEDIR), '-x')
1640         rotate = pi;
1641     else rotate = pi/2;
1642     end;
1643     allcoords = (inty + intx*sqrt(-1))*exp(sqrt(-1)*rotate);
1644     intx = imag(allcoords);
1645     inty = real(allcoords);
1646     allcoords = (ally + allx*sqrt(-1))*exp(sqrt(-1)*rotate);
1647     allx = imag(allcoords);
1648     ally = real(allcoords);
1649     allcoords = (y + x*sqrt(-1))*exp(sqrt(-1)*rotate);
1650     x = imag(allcoords);
1651     y = real(allcoords);
1652 end;
1653 
1654 %
1655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Make the plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1656 %
1657 if ~strcmpi(STYLE,'blank') % if draw interpolated scalp map
1658     if ~strcmpi(STYLE,'grid') %  not a rectangular channel grid
1659         %
1660         %%%%%%%%%%%%%%%% Find limits for interpolation %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1661         %
1662         if default_intrad % if no specified intrad
1663             if strcmpi(INTERPLIMITS,'head') % intrad is 'head'
1664                 xmin = min(-rmax,min(intx)); xmax = max(rmax,max(intx));
1665                 ymin = min(-rmax,min(inty)); ymax = max(rmax,max(inty));
1666                 
1667             else % INTERPLIMITS = rectangle containing electrodes -- DEPRECATED OPTION!
1668                 xmin = max(-rmax,min(intx)); xmax = min(rmax,max(intx));
1669                 ymin = max(-rmax,min(inty)); ymax = min(rmax,max(inty));
1670             end
1671         else % some other intrad specified
1672             xmin = -intrad*squeezefac; xmax = intrad*squeezefac;   % use the specified intrad value
1673             ymin = -intrad*squeezefac; ymax = intrad*squeezefac;
1674         end
1675         %
1676         %%%%%%%%%%%%%%%%%%%%%%% Interpolate scalp map data %%%%%%%%%%%%%%%%%%%%%%%%
1677         %
1678         xi = linspace(xmin,xmax,GRID_SCALE);   % x-axis description (row vector)
1679         yi = linspace(ymin,ymax,GRID_SCALE);   % y-axis description (row vector)
1680         
1681         [Xi,Yi,Zi] = griddata2(inty,intx,intValues,yi',xi,'invdist'); % interpolate data
1682         [Xi,Yi,ZiC] = griddata2(inty,intx,intContourVals,yi',xi,'invdist'); % interpolate data
1683         
1684         %
1685         %%%%%%%%%%%%%%%%%%%%%%% Mask out data outside the head %%%%%%%%%%%%%%%%%%%%%
1686         %
1687         mask = (sqrt(Xi.^2 + Yi.^2) <= rmax); % mask outside the plotting circle
1688         ii = find(mask == 0);
1689         Zi(ii)  = NaN;                         % mask non-plotting voxels with NaNs
1690         ZiC(ii) = NaN;                         % mask non-plotting voxels with NaNs
1691         grid = plotrad;                       % unless 'noplot', then 3rd output arg is plotrad
1692         %
1693         %%%%%%%%%% Return interpolated value at designated scalp location %%%%%%%%%%
1694         %
1695         if exist('chanrad')   % optional first argument to 'noplot'
1696             chantheta = (chantheta/360)*2*pi;
1697             chancoords = round(ceil(GRID_SCALE/2)+GRID_SCALE/2*2*chanrad*[cos(-chantheta),...
1698                 -sin(-chantheta)]);
1699             if chancoords(1)<1 ...
1700                     | chancoords(1) > GRID_SCALE ...
1701                     | chancoords(2)<1 ...
1702                     | chancoords(2)>GRID_SCALE
1703                 error('designated ''noplot'' channel out of bounds')
1704             else
1705                 chanval = Zi(chancoords(1),chancoords(2));
1706                 grid = Zi;
1707                 Zi = chanval;  % return interpolated value instead of Zi
1708             end
1709         end
1710         %
1711         %%%%%%%%%%%%%%%%%%%%%%%%%% Return interpolated image only  %%%%%%%%%%%%%%%%%
1712         %
1713         if strcmpi(noplot, 'on')
1714             if strcmpi(VERBOSE,'on')
1715                 fprintf('topoplot(): no plot requested.\n')
1716             end
1717             return;
1718         end
1719         %
1720         %%%%%%%%%%%%%%%%%%%%%%% Calculate colormap limits %%%%%%%%%%%%%%%%%%%%%%%%%%
1721         %
1722         if isstr(MAPLIMITS)
1723             if strcmp(MAPLIMITS,'absmax')
1724                 amax = max(max(abs(Zi)));
1725                 amin = -amax;
1726             elseif strcmp(MAPLIMITS,'maxmin') | strcmp(MAPLIMITS,'minmax')
1727                 amin = min(min(Zi));
1728                 amax = max(max(Zi));
1729             else
1730                 error('unknown ''maplimits'' value.');
1731             end
1732         elseif length(MAPLIMITS) == 2
1733             amin = MAPLIMITS(1);
1734             amax = MAPLIMITS(2);
1735         else
1736             error('unknown ''maplimits'' value');
1737         end
1738         delta = xi(2)-xi(1); % length of grid entry
1739         
1740     end % if ~strcmpi(STYLE,'grid')
1741     %
1742     %%%%%%%%%%%%%%%%%%%%%%%%%% Scale the axes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1743     %
1744     cla  % clear current axis
1745     hold on
1746     h = gca; % uses current axes
1747     
1748     % instead of default larger AXHEADFAC
1749     if squeezefac<0.92 & plotrad-headrad > 0.05  % (size of head in axes)
1750         AXHEADFAC = 1.05;     % do not leave room for external ears if head cartoon
1751         % shrunk enough by the 'skirt' option
1752     end
1753     
1754     set(gca,'Xlim',[-rmax rmax]*AXHEADFAC,'Ylim',[-rmax rmax]*AXHEADFAC);
1755     % specify size of head axes in gca
1756     
1757     unsh = (GRID_SCALE+1)/GRID_SCALE; % un-shrink the effects of 'interp' SHADING
1758     
1759     %
1760     %%%%%%%%%%%%%%%%%%%%%%%% Plot grid only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1761     %
1762     if strcmpi(STYLE,'grid')                     % plot grid only
1763         
1764         %
1765         % The goal below is to make the grid cells square - not yet achieved in all cases? -sm
1766         %
1767         g1 = size(gridchans,1);
1768         g2 = size(gridchans,2);
1769         gmax = max([g1 g2]);
1770         Xi = linspace(-rmax*g2/gmax,rmax*g2/gmax,g1+1);
1771         Xi = Xi+rmax/g1; Xi = Xi(1:end-1);
1772         Yi = linspace(-rmax*g1/gmax,rmax*g1/gmax,g2+1);
1773         Yi = Yi+rmax/g2; Yi = Yi(1:end-1); Yi = Yi(end:-1:1); % by trial and error!
1774         %
1775         %%%%%%%%%%% collect the gridchans values %%%%%%%%%%%%%%%%%%%%%%%%%%%
1776         %
1777         gridvalues = zeros(size(gridchans));
1778         for j=1:size(gridchans,1)
1779             for k=1:size(gridchans,2)
1780                 gc = gridchans(j,k);
1781                 if gc > 0
1782                     gridvalues(j,k) = Values(gc);
1783                 elseif gc < 0
1784                     gridvalues(j,k) = -Values(gc);
1785                 else
1786                     gridvalues(j,k) = nan; % not-a-number = no value
1787                 end
1788             end
1789         end
1790         %
1791         %%%%%%%%%%% reset color limits for grid plot %%%%%%%%%%%%%%%%%%%%%%%%%
1792         %
1793         if isstr(MAPLIMITS)
1794             if strcmp(MAPLIMITS,'maxmin') | strcmp(MAPLIMITS,'minmax')
1795                 amin = min(min(gridvalues(~isnan(gridvalues))));
1796                 amax = max(max(gridvalues(~isnan(gridvalues))));
1797             elseif strcmp(MAPLIMITS,'absmax')
1798                 % 11/21/2005 Toby edit
1799                 % This should now work as specified. Before it only crashed (using
1800                 % "plotgrid" and "maplimits>absmax" options).
1801                 amax = max(max(abs(gridvalues(~isnan(gridvalues)))));
1802                 amin = -amax;
1803                 %amin = -max(max(abs([amin amax])));
1804                 %amax = max(max(abs([amin amax])));
1805             else
1806                 error('unknown ''maplimits'' value');
1807             end
1808         elseif length(MAPLIMITS) == 2
1809             amin = MAPLIMITS(1);
1810             amax = MAPLIMITS(2);
1811         else
1812             error('unknown ''maplimits'' value');
1813         end
1814         %
1815         %%%%%%%%%% explicitly compute grid colors, allowing BACKCOLOR  %%%%%%
1816         %
1817         gridvalues = 1+floor(cmaplen*(gridvalues-amin)/(amax-amin));
1818         gridvalues(find(gridvalues == cmaplen+1)) = cmaplen;
1819         gridcolors = zeros([size(gridvalues),3]);
1820         for j=1:size(gridchans,1)
1821             for k=1:size(gridchans,2)
1822                 if ~isnan(gridvalues(j,k))
1823                     gridcolors(j,k,:) = cmap(gridvalues(j,k),:);
1824                 else
1825                     if strcmpi(whitebk,'off')
1826                         gridcolors(j,k,:) = BACKCOLOR; % gridchans == 0 -> background color
1827                         % This allows the plot to show 'space' between separate sub-grids or strips
1828                     else % 'on'
1829                         gridcolors(j,k,:) = [1 1 1]; BACKCOLOR; % gridchans == 0 -> white for printing
1830                     end
1831                 end
1832             end
1833         end
1834         
1835         %
1836         %%%%%%%%%% draw the gridplot image %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1837         %
1838         handle=imagesc(Xi,Yi,gridcolors); % plot grid with explicit colors
1839         axis square
1840         
1841         %
1842         %%%%%%%%%%%%%%%%%%%%%%%% Plot map contours only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1843         %
1844     elseif strcmp(STYLE,'contour')                     % plot surface contours only
1845         [cls chs] = contour(Xi,Yi,ZiC,CONTOURNUM,'k');
1846         % for h=chs, set(h,'color',CCOLOR); end
1847         %
1848         %%%%%%%%%%%%%%%%%%%%%%%% Else plot map and contours %%%%%%%%%%%%%%%%%%%%%%%%%
1849         %
1850     elseif strcmp(STYLE,'both')  % plot interpolated surface and surface contours
1851         if strcmp(SHADING,'interp')
1852             tmph = surface(Xi*unsh,Yi*unsh,zeros(size(Zi))-0.1,Zi,...
1853                 'EdgeColor','none','FaceColor',SHADING);
1854         else % SHADING == 'flat'
1855             tmph = surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi))-0.1,Zi,...
1856                 'EdgeColor','none','FaceColor',SHADING);
1857         end
1858         if strcmpi(MASKSURF, 'on')
1859             set(tmph, 'visible', 'off');
1860             handle = tmph;
1861         end;
1862         
1863         if ~PMASKFLAG
1864             [cls chs] = contour(Xi,Yi,ZiC,CONTOURNUM,'k');
1865         else
1866             ZiC(find(ZiC > 0.5 )) = NaN;
1867             [cls chs] = contourf(Xi,Yi,ZiC,0,'k');
1868             subh = get(chs, 'children');
1869             for indsubh = 1:length(subh)
1870                 numfaces = size(get(subh(indsubh), 'XData'),1);
1871                 set(subh(indsubh), 'FaceVertexCData', ones(numfaces,3), 'Cdatamapping', 'direct', 'facealpha', 0.5);
1872             end;
1873         end;
1874         for h=chs, set(h,'color',CCOLOR); end
1875         
1876         %
1877         %%%%%%%%%%%%%%%%%%%%%%%% Else plot map only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1878         %
1879     elseif strcmp(STYLE,'straight') | strcmp(STYLE,'map') % 'straight' was former arg
1880         
1881         if strcmp(SHADING,'interp') % 'interp' mode is shifted somehow... but how?
1882             tmph = surface(Xi*unsh,Yi*unsh,zeros(size(Zi)),Zi,'EdgeColor','none',...
1883                 'FaceColor',SHADING);
1884         else
1885             tmph = surface(Xi-delta/2,Yi-delta/2,zeros(size(Zi)),Zi,'EdgeColor','none',...
1886                 'FaceColor',SHADING);
1887         end
1888         if strcmpi(MASKSURF, 'on')
1889             set(tmph, 'visible', 'off');
1890             handle = tmph;
1891         end;
1892         %
1893         %%%%%%%%%%%%%%%%%% Else fill contours with uniform colors  %%%%%%%%%%%%%%%%%%
1894         %
1895     elseif strcmp(STYLE,'fill')
1896         [cls chs] = contourf(Xi,Yi,Zi,CONTOURNUM,'k');
1897         
1898         % for h=chs, set(h,'color',CCOLOR); end
1899         %     <- 'not line objects.' Why does 'both' work above???
1900         
1901     else
1902         error('Invalid style')
1903     end
1904     %
1905     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Set color axis  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1906     %
1907     caxis([amin amax]); % set coloraxis
1908     
1909 else % if STYLE 'blank'
1910     %
1911     %%%%%%%%%%%%%%%%%%%%%%% Draw blank head %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1912     %
1913     if strcmpi(noplot, 'on')
1914         if strcmpi(VERBOSE,'on')
1915             fprintf('topoplot(): no plot requested.\n')
1916         end
1917         return;
1918     end
1919     cla
1920     hold on
1921     
1922     set(gca,'Xlim',[-rmax rmax]*AXHEADFAC,'Ylim',[-rmax rmax]*AXHEADFAC)
1923     % pos = get(gca,'position');
1924     % fprintf('Current axes size %g,%g\n',pos(3),pos(4));
1925     if ~plain_blank,
1926         if strcmp(ELECTRODES,'labelpoint') |  strcmp(ELECTRODES,'numpoint')
1927             text(-0.6,-0.6, ...
1928                 [ int2str(length(Rd)) ' of ' int2str(length(tmpeloc)) ' electrode locations shown']);
1929             text(-0.6,-0.7, [ 'Click on electrodes to toggle name/number']);
1930             tl = title('Channel locations');
1931             set(tl, 'fontweight', 'bold');
1932         end;
1933     end
1934 end % STYLE 'blank'
1935 
1936 if exist('handle') ~= 1
1937     handle = gca;
1938 end;
1939 
1940 if ~strcmpi(STYLE,'grid')                     % if not plot grid only
1941     
1942     %
1943     %%%%%%%%%%%%%%%%%%% Plot filled ring to mask jagged grid boundary %%%%%%%%%%%%%%%%%%%%%%%%%%%
1944     %
1945     hwidth = HEADRINGWIDTH;                   % width of head ring
1946     hin  = squeezefac*headrad*(1- hwidth/2);  % inner head ring radius
1947     
1948     if strcmp(SHADING,'interp')
1949         rwidth = BLANKINGRINGWIDTH*1.3;             % width of blanking outer ring
1950     else
1951         rwidth = BLANKINGRINGWIDTH;         % width of blanking outer ring
1952     end
1953     rin    =  rmax*(1-rwidth/2);              % inner ring radius
1954     if hin>rin
1955         rin = hin;                              % dont blank inside the head ring
1956     end
1957     
1958     if strcmp(CONVHULL,'on') %%%%%%%%% mask outside the convex hull of the electrodes %%%%%%%%%
1959         cnv = convhull(allx,ally);
1960         cnvfac = round(CIRCGRID/length(cnv)); % spline interpolate the convex hull
1961         if cnvfac < 1, cnvfac=1; end;
1962         CIRCGRID = cnvfac*length(cnv);
1963         
1964         startangle = atan2(allx(cnv(1)),ally(cnv(1)));
1965         circ = linspace(0+startangle,2*pi+startangle,CIRCGRID);
1966         rx = sin(circ);
1967         ry = cos(circ);
1968         
1969         allx = allx(:)';  % make x (elec locations; + to nose) a row vector
1970         ally = ally(:)';  % make y (elec locations, + to r? ear) a row vector
1971         erad = sqrt(allx(cnv).^2+ally(cnv).^2);  % convert to polar coordinates
1972         eang = atan2(allx(cnv),ally(cnv));
1973         eang = unwrap(eang);
1974         eradi =spline(linspace(0,1,3*length(cnv)), [erad erad erad], ...
1975             linspace(0,1,3*length(cnv)*cnvfac));
1976         eangi =spline(linspace(0,1,3*length(cnv)), [eang+2*pi eang eang-2*pi], ...
1977             linspace(0,1,3*length(cnv)*cnvfac));
1978         xx = eradi.*sin(eangi);           % convert back to rect coordinates
1979         yy = eradi.*cos(eangi);
1980         yy = yy(CIRCGRID+1:2*CIRCGRID);
1981         xx = xx(CIRCGRID+1:2*CIRCGRID);
1982         eangi = eangi(CIRCGRID+1:2*CIRCGRID);
1983         eradi = eradi(CIRCGRID+1:2*CIRCGRID);
1984         xx = xx*1.02; yy = yy*1.02;           % extend spline outside electrode marks
1985         
1986         splrad = sqrt(xx.^2+yy.^2);           % arc radius of spline points (yy,xx)
1987         oob = find(splrad >= rin);            %  enforce an upper bound on xx,yy
1988         xx(oob) = rin*xx(oob)./splrad(oob);   % max radius = rin
1989         yy(oob) = rin*yy(oob)./splrad(oob);   % max radius = rin
1990         
1991         splrad = sqrt(xx.^2+yy.^2);           % arc radius of spline points (yy,xx)
1992         oob = find(splrad < hin);             % don't let splrad be inside the head cartoon
1993         xx(oob) = hin*xx(oob)./splrad(oob);   % min radius = hin
1994         yy(oob) = hin*yy(oob)./splrad(oob);   % min radius = hin
1995         
1996         ringy = [[ry(:)' ry(1) ]*(rin+rwidth) yy yy(1)];
1997         ringx = [[rx(:)' rx(1) ]*(rin+rwidth) xx xx(1)];
1998         
1999         ringh2= patch(ringy,ringx,ones(size(ringy)),BACKCOLOR,'edgecolor','none'); hold on
2000         
2001         % plot(ry*rmax,rx*rmax,'b') % debugging line
2002         
2003     else %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mask the jagged border around rmax %%%%%%%%%%%%%%%5%%%%%%
2004         
2005         circ = linspace(0,2*pi,CIRCGRID);
2006         rx = sin(circ);
2007         ry = cos(circ);
2008         ringx = [[rx(:)' rx(1) ]*(rin+rwidth)  [rx(:)' rx(1)]*rin];
2009         ringy = [[ry(:)' ry(1) ]*(rin+rwidth)  [ry(:)' ry(1)]*rin];
2010         
2011         if ~strcmpi(STYLE,'blank')
2012             ringh= patch(ringx,ringy,0.01*ones(size(ringx)),BACKCOLOR,'edgecolor','none'); hold on
2013         end
2014         % plot(ry*rmax,rx*rmax,'b') % debugging line
2015     end
2016     
2017     %f1= fill(rin*[rx rX],rin*[ry rY],BACKCOLOR,'edgecolor',BACKCOLOR); hold on
2018     %f2= fill(rin*[rx rX*(1+rwidth)],rin*[ry rY*(1+rwidth)],BACKCOLOR,'edgecolor',BACKCOLOR);
2019     
2020     % Former line-style border smoothing - width did not scale with plot
2021     %  brdr=plot(1.015*cos(circ).*rmax,1.015*sin(circ).*rmax,...      % old line-based method
2022     %      'color',HEADCOLOR,'Linestyle','-','LineWidth',HLINEWIDTH);    % plot skirt outline
2023     %  set(brdr,'color',BACKCOLOR,'linewidth',HLINEWIDTH + 4);        % hide the disk edge jaggies
2024     
2025     %
2026     %%%%%%%%%%%%%%%%%%%%%%%%% Plot cartoon head, ears, nose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2027     %
2028     if headrad > 0                         % if cartoon head to be plotted
2029         %
2030         %%%%%%%%%%%%%%%%%%% Plot head outline %%%%%%%%%%%%%%%%%%%%%%%%%%%
2031         %
2032         headx = [[rx(:)' rx(1) ]*(hin+hwidth)  [rx(:)' rx(1)]*hin];
2033         heady = [[ry(:)' ry(1) ]*(hin+hwidth)  [ry(:)' ry(1)]*hin];
2034         
2035         if ~isstr(HEADCOLOR) | ~strcmpi(HEADCOLOR,'none')
2036             ringh= patch(headx,heady,ones(size(headx)),HEADCOLOR,'edgecolor',HEADCOLOR); hold on
2037         end
2038         
2039         % rx = sin(circ); rX = rx(end:-1:1);
2040         % ry = cos(circ); rY = ry(end:-1:1);
2041         % for k=2:2:CIRCGRID
2042         %   rx(k) = rx(k)*(1+hwidth);
2043         %   ry(k) = ry(k)*(1+hwidth);
2044         % end
2045         % f3= fill(hin*[rx rX],hin*[ry rY],HEADCOLOR,'edgecolor',HEADCOLOR); hold on
2046         % f4= fill(hin*[rx rX*(1+hwidth)],hin*[ry rY*(1+hwidth)],HEADCOLOR,'edgecolor',HEADCOLOR);
2047         
2048         % Former line-style head
2049         %  plot(cos(circ).*squeezefac*headrad,sin(circ).*squeezefac*headrad,...
2050         %      'color',HEADCOLOR,'Linestyle','-','LineWidth',HLINEWIDTH);    % plot head outline
2051         
2052         %
2053         %%%%%%%%%%%%%%%%%%% Plot ears and nose %%%%%%%%%%%%%%%%%%%%%%%%%%%
2054         %
2055         base  = rmax-.0046;
2056         basex = 0.18*rmax;                   % nose width
2057         tip   = 1.15*rmax;
2058         tiphw = .04*rmax;                    % nose tip half width
2059         tipr  = .01*rmax;                    % nose tip rounding
2060         q = .04; % ear lengthening
2061         EarX  = [.497-.005  .510  .518  .5299 .5419  .54    .547   .532   .510   .489-.005]; % rmax = 0.5
2062         EarY  = [q+.0555 q+.0775 q+.0783 q+.0746 q+.0555 -.0055 -.0932 -.1313 -.1384 -.1199];
2063         sf    = headrad/plotrad;                                          % squeeze the model ears and nose
2064         % by this factor
2065         if ~isstr(HEADCOLOR) | ~strcmpi(HEADCOLOR,'none')
2066             plot3([basex;tiphw;0;-tiphw;-basex]*sf,[base;tip-tipr;tip;tip-tipr;base]*sf,...
2067                 2*ones(size([basex;tiphw;0;-tiphw;-basex])),...
2068                 'Color',HEADCOLOR,'LineWidth',HLINEWIDTH);                 % plot nose
2069             plot3(EarX*sf,EarY*sf,2*ones(size(EarX)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH)    % plot left ear
2070             plot3(-EarX*sf,EarY*sf,2*ones(size(EarY)),'color',HEADCOLOR,'LineWidth',HLINEWIDTH)   % plot right ear
2071         end
2072     end
2073     
2074     %
2075     % %%%%%%%%%%%%%%%%%%% Show electrode information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2076     %
2077     plotax = gca;
2078     axis square                                           % make plotax square
2079     axis off
2080     
2081     pos = get(gca,'position');
2082     xlm = get(gca,'xlim');
2083     ylm = get(gca,'ylim');
2084     % textax = axes('position',pos,'xlim',xlm,'ylim',ylm);  % make new axes so clicking numbers <-> labels
2085     % will work inside head cartoon patch
2086     % axes(textax);
2087     axis square                                           % make textax square
2088     
2089     pos = get(gca,'position');
2090     set(plotax,'position',pos);
2091     
2092     xlm = get(gca,'xlim');
2093     set(plotax,'xlim',xlm);
2094     
2095     ylm = get(gca,'ylim');
2096     set(plotax,'ylim',ylm);                               % copy position and axis limits again
2097     
2098     %get(textax,'pos')    % test if equal!
2099     %get(plotax,'pos')
2100     %get(textax,'xlim')
2101     %get(plotax,'xlim')
2102     %get(textax,'ylim')
2103     %get(plotax,'ylim')
2104     
2105     if isempty(EMARKERSIZE)
2106         EMARKERSIZE = 10;
2107         if length(y)>=160
2108             EMARKERSIZE = 3;
2109         elseif length(y)>=128
2110             EMARKERSIZE = 3;
2111         elseif length(y)>=100
2112             EMARKERSIZE = 3;
2113         elseif length(y)>=80
2114             EMARKERSIZE = 4;
2115         elseif length(y)>=64
2116             EMARKERSIZE = 8; %wad 5
2117         elseif length(y)>=48
2118             EMARKERSIZE = 10; %was 6
2119         elseif length(y)>=32
2120             EMARKERSIZE = 10; %was 8
2121         end
2122     end
2123     %
2124     %%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations only %%%%%%%%%%%%%%%%%%%%%%%%%%
2125     %
2126     ELECTRODE_HEIGHT = 2.1;  % z value for plotting electrode information (above the surf)
2127     
2128     if strcmp(ELECTRODES,'on')   % plot electrodes as spots
2129         if isempty(EMARKER2CHANS)
2130             for i=1:length(y),
2131                 %        hp2 = plot3(y(i),x(i),1*ELECTRODE_HEIGHT,...
2132                 %            EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH, ...
2133                 %            'buttondownfcn',['set(gco,''color'',''r'');']);
2134                 %DG?? I added the below in place of the code above so that you
2135                 %could click on electrodes and see the name
2136                 hp2 = plot3(y(i),x(i),ELECTRODE_HEIGHT,...
2137                     EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2138                 set(hp2,'tag',str2lowcase(strtok(labels(i,:)))); %get rid of extra spaces and convert to lowercase
2139                 hh(i) = text(double(y(i)+0.01),double(x(i)),...
2140                     ELECTRODE_HEIGHT,'   ','HorizontalAlignment','center',...
2141                     'VerticalAlignment','middle','Color', ECOLOR,'userdata', labels(i,:) , ...
2142                     'FontSize',round(EFSIZE*1), 'fontunits','normalized','buttondownfcn', ...
2143                     ['tmpstr = get(gco, ''userdata'');' ...
2144                     'set(gco, ''userdata'', get(gco, ''string''));' ...
2145                     'set(gco, ''string'', tmpstr); clear tmpstr; if strcmpi(get(gco,''backgroundcolor''),''none''),' ...
2146                     'set(gco,''backgroundcolor'',''w''); else set(gco,''backgroundcolor'',''none''); end;'] );
2147             end
2148         else % plot markers for normal chans and EMARKER2CHANS separately
2149             % DG added start
2150             if size(mark1chans,1)>1
2151                 mark1chans=mark1chans';
2152             end
2153             if size(mark2chans,1)>1
2154                 mark2chans=mark2chans';
2155             end
2156             % DG added stop
2157             
2158             for i=mark1chans,
2159                 hp2 = plot3(y(i),x(i),ELECTRODE_HEIGHT,...
2160                     EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2161                 set(hp2,'tag',str2lowcase(strtok(labels(i,:)))); %get rid of extra spaces and convert to lowercase
2162             end
2163             for i=mark2chans,
2164                 hp2b = plot3(y(i),x(i),ELECTRODE_HEIGHT,...
2165                     EMARKER2,'Color',EMARKER2COLOR,'markerfacecolor',EMARKER2COLOR,'linewidth',EMARKER2LINEWIDTH,'markersize',EMARKERSIZE2);
2166                 set(hp2b,'tag',str2lowcase(strtok(labels(i,:)))); %get rid of extra spaces and convert to lowercase
2167             end
2168             for i=1:length(y),
2169                 hh(i) = text(double(y(i)+0.01),double(x(i)),...
2170                     ELECTRODE_HEIGHT,'   ','HorizontalAlignment','center',...
2171                     'VerticalAlignment','middle','Color', ECOLOR,'userdata', labels(i,:) , ...
2172                     'FontSize',round(EFSIZE*1), 'fontunits','normalized','buttondownfcn', ...
2173                     ['tmpstr = get(gco, ''userdata'');' ...
2174                     'set(gco, ''userdata'', get(gco, ''string''));' ...
2175                     'set(gco, ''string'', tmpstr); clear tmpstr; if strcmpi(get(gco,''backgroundcolor''),''none''),' ...
2176                     'set(gco,''backgroundcolor'',''w''); else set(gco,''backgroundcolor'',''none''); end;'] );
2177             end
2178         end
2179         %
2180         %%%%%%%%%%%%%%%%%%%%%%%% Print electrode labels only %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2181         %
2182     elseif strcmp(ELECTRODES,'labels')  % print electrode names (labels)
2183         for i = 1:size(labels,1)
2184             text(double(y(i)),double(x(i)),...
2185                 ELECTRODE_HEIGHT,labels(i,:),'HorizontalAlignment','center',...
2186                 'VerticalAlignment','middle','Color',ECOLOR,...
2187                 'FontSize',EFSIZE)
2188         end
2189         %
2190         %%%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations plus labels %%%%%%%%%%%%%%%%%%%
2191         %
2192     elseif strcmp(ELECTRODES,'labelpoint')
2193         if isempty(EMARKER2CHANS)
2194             hp2 = plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,...
2195                 EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2196         else
2197             hp2 = plot3(y(mark1chans),x(mark1chans),ones(size((mark1chans)))*ELECTRODE_HEIGHT,...
2198                 EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2199             hp2b = plot3(y(mark2chans),x(mark2chans),ones(size((mark2chans)))*ELECTRODE_HEIGHT,...
2200                 EMARKER2,'Color',EMARKER2COLOR,'markerfacecolor',EMARKER2COLOR,'linewidth',EMARKER2LINEWIDTH,'markersize',EMARKERSIZE2);
2201         end
2202         for i = 1:size(labels,1)
2203             hh(i) = text(double(y(i)+0.01),double(x(i)),...
2204                 ELECTRODE_HEIGHT,labels(i,:),'HorizontalAlignment','left',...
2205                 'VerticalAlignment','middle','Color', ECOLOR,'userdata', num2str(allchansind(i)), ...
2206                 'FontSize',EFSIZE, 'buttondownfcn', ...
2207                 ['tmpstr = get(gco, ''userdata'');'...
2208                 'set(gco, ''userdata'', get(gco, ''string''));' ...
2209                 'set(gco, ''string'', tmpstr); clear tmpstr;'] );
2210         end
2211         %
2212         %%%%%%%%%%%%%%%%%%%%%%% Mark electrode locations plus numbers %%%%%%%%%%%%%%%%%%%
2213         %
2214     elseif strcmp(ELECTRODES,'numpoint')
2215         if isempty(EMARKER2CHANS)
2216             hp2 = plot3(y,x,ones(size(x))*ELECTRODE_HEIGHT,...
2217                 EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2218         else
2219             hp2 = plot3(y(mark1chans),x(mark1chans),ones(size((mark1chans)))*ELECTRODE_HEIGHT,...
2220                 EMARKER,'Color',ECOLOR,'markersize',EMARKERSIZE,'linewidth',EMARKERLINEWIDTH);
2221             hp2b = plot3(y(mark2chans),x(mark2chans),ones(size((mark2chans)))*ELECTRODE_HEIGHT,...
2222                 EMARKER2,'Color',EMARKER2COLOR,'markerfacecolor',EMARKER2COLOR,'linewidth',EMARKER2LINEWIDTH,'markersize',EMARKERSIZE2);
2223         end
2224         for i = 1:size(labels,1)
2225             hh(i) = text(double(y(i)+0.01),double(x(i)),...
2226                 ELECTRODE_HEIGHT,num2str(allchansind(i)),'HorizontalAlignment','left',...
2227                 'VerticalAlignment','middle','Color', ECOLOR,'userdata', labels(i,:) , ...
2228                 'FontSize',EFSIZE, 'buttondownfcn', ...
2229                 ['tmpstr = get(gco, ''userdata'');'...
2230                 'set(gco, ''userdata'', get(gco, ''string''));' ...
2231                 'set(gco, ''string'', tmpstr); clear tmpstr;'] );
2232         end
2233         %
2234         %%%%%%%%%%%%%%%%%%%%%% Print electrode numbers only %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2235         %
2236     elseif strcmp(ELECTRODES,'numbers')
2237         for i = 1:size(labels,1)
2238             text(double(y(i)),double(x(i)),...
2239                 ELECTRODE_HEIGHT,int2str(allchansind(i)),'HorizontalAlignment','center',...
2240                 'VerticalAlignment','middle','Color',ECOLOR,...
2241                 'FontSize',EFSIZE)
2242         end
2243         %
2244         %%%%%%%%%%%%%%%%%%%%%% Mark emarker2 electrodes only  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2245         %
2246     elseif strcmp(ELECTRODES,'off') & ~isempty(EMARKER2CHANS)
2247         hp2b = plot3(y(mark2chans),x(mark2chans),ones(size((mark2chans)))*ELECTRODE_HEIGHT,...
2248             EMARKER2,'Color',EMARKER2COLOR,'markerfacecolor',EMARKER2COLOR,'linewidth',EMARKER2LINEWIDTH,'markersize',EMARKERSIZE2);
2249     end
2250     %
2251     %%%%%%%% Mark specified electrode locations with red filled disks  %%%%%%%%%%%%%%%%%%%%%%
2252     %
2253     if ~plain_blank,
2254         try,
2255             if strcmpi(STYLE,'blank') % if mark-selected-channel-locations mode
2256                 if strcmpi(ELECTRODES,'on') | strcmpi(ELECTRODES,'off')
2257                     for kk = 1:length(plotchans)
2258                         if strcmpi(EMARKER,'.')
2259                             hp2 = plot3(y(kk),x(kk),ELECTRODE_HEIGHT,EMARKER,'Color', EMARKERCOLOR1CHAN, ...
2260                                 'markersize', EMARKERSIZE1CHAN);
2261                         else
2262                             hp2 = plot3(y(kk),x(kk),ELECTRODE_HEIGHT,EMARKER,'Color', EMARKERCOLOR1CHAN, ...
2263                                 'markersize', EMARKERSIZE1CHAN);
2264                         end
2265                     end
2266                     hold on
2267                 end
2268             end
2269         catch, end;
2270     end
2271     %
2272     %%%%%%%%%%%%%%%%%%%%%%%%%%% Plot dipole(s) on the scalp map  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2273     %
2274     if ~isempty(DIPOLE)
2275         hold on;
2276         tmp = DIPOLE;
2277         if isstruct(DIPOLE)
2278             if ~isfield(tmp,'posxyz')
2279                 error('dipole structure is not an EEG.dipfit.model')
2280             end
2281             DIPOLE = [];  % Note: invert x and y from dipplot usage
2282             DIPOLE(:,1) = -tmp.posxyz(:,2)/DIPSPHERE; % -y -> x
2283             DIPOLE(:,2) =  tmp.posxyz(:,1)/DIPSPHERE; %  x -> y
2284             DIPOLE(:,3) = -tmp.momxyz(:,2);
2285             DIPOLE(:,4) =  tmp.momxyz(:,1);
2286         else
2287             DIPOLE(:,1) = -tmp(:,2);                    % same for vector input
2288             DIPOLE(:,2) =  tmp(:,1);
2289             DIPOLE(:,3) = -tmp(:,4);
2290             DIPOLE(:,4) =  tmp(:,3);
2291         end;
2292         for index = 1:size(DIPOLE,1)
2293             if ~any(DIPOLE(index,:))
2294                 DIPOLE(index,:) = [];
2295             end
2296         end;
2297         DIPOLE(:,1:4)   = DIPOLE(:,1:4)*rmax*(rmax/plotrad); % scale radius from 1 -> rmax (0.5)
2298         DIPOLE(:,3:end) = (DIPOLE(:,3:end))*rmax/100000*(rmax/plotrad);
2299         if strcmpi(DIPNORM, 'on')
2300             for index = 1:size(DIPOLE,1)
2301                 DIPOLE(index,3:4) = DIPOLE(index,3:4)/norm(DIPOLE(index,3:end))*0.2;
2302             end;
2303         end;
2304         DIPOLE(:, 3:4) =  DIPORIENT*DIPOLE(:, 3:4)*DIPLEN;
2305         
2306         PLOT_DIPOLE=1;
2307         if sum(DIPOLE(1,3:4).^2) <= 0.00001
2308             if strcmpi(VERBOSE,'on')
2309                 fprintf('Note: dipole is length 0 - not plotted\n')
2310             end
2311             PLOT_DIPOLE = 0;
2312         end
2313         if 0 % sum(DIPOLE(1,1:2).^2) > plotrad
2314             if strcmpi(VERBOSE,'on')
2315                 fprintf('Note: dipole is outside plotting area - not plotted\n')
2316             end
2317             PLOT_DIPOLE = 0;
2318         end
2319         if PLOT_DIPOLE
2320             for index = 1:size(DIPOLE,1)
2321                 hh = plot( DIPOLE(index, 1), DIPOLE(index, 2), '.');
2322                 set(hh, 'color', DIPCOLOR, 'markersize', DIPSCALE*30);
2323                 hh = line( [DIPOLE(index, 1) DIPOLE(index, 1)+DIPOLE(index, 3)]', ...
2324                     [DIPOLE(index, 2) DIPOLE(index, 2)+DIPOLE(index, 4)]',[10 10]);
2325                 set(hh, 'color', DIPCOLOR, 'linewidth', DIPSCALE*30/7);
2326             end;
2327         end;
2328     end;
2329     
2330 end % if ~ 'gridplot'
2331 
2332 %
2333 %%%%%%%%%%%%% Plot axis orientation %%%%%%%%%%%%%%%%%%%%
2334 %
2335 if strcmpi(DRAWAXIS, 'on')
2336     axes('position', [0 0.85 0.08 0.1]);
2337     axis off;
2338     coordend1 = sqrt(-1)*3;
2339     coordend2 = -3;
2340     coordend1 = coordend1*exp(sqrt(-1)*rotate);
2341     coordend2 = coordend2*exp(sqrt(-1)*rotate);
2342     
2343     line([5 5+round(real(coordend1))]', [5 5+round(imag(coordend1))]', 'color', 'k');
2344     line([5 5+round(real(coordend2))]', [5 5+round(imag(coordend2))]', 'color', 'k');
2345     if round(real(coordend2))<0
2346         text( 5+round(real(coordend2))*1.2, 5+round(imag(coordend2))*1.2-2, '+Y');
2347     else text( 5+round(real(coordend2))*1.2, 5+round(imag(coordend2))*1.2, '+Y');
2348     end;
2349     if round(real(coordend1))<0
2350         text( 5+round(real(coordend1))*1.2, 5+round(imag(coordend1))*1.2+1.5, '+X');
2351     else text( 5+round(real(coordend1))*1.2, 5+round(imag(coordend1))*1.2, '+X');
2352     end;
2353     set(gca, 'xlim', [0 10], 'ylim', [0 10]);
2354 end;
2355 
2356 %
2357 %%%%%%%%%%%%% Set EEGLAB background color to match head border %%%%%%%%%%%%%%%%%%%%%%%%
2358 %
2359 try,
2360     icadefs;
2361     set(gcf, 'color', BACKCOLOR);
2362 catch,
2363 end;
2364 
2365 hold off
2366 axis off
2367 return
2368 
2369 
2370 
2371 function lowcase=str2lowcase(str)
2372 
2373 n=length(str);
2374 lowcase=zeros(1,n);
2375 for a=1:n,
2376     if (str(a)>=65) && (str(a)<=90)
2377         lowcase(a)=str(a)+32;
2378     else
2379         lowcase(a)=str(a);
2380     end
2381 end
2382 lowcase=char(lowcase);
2383

Generated on Tue 10-May-2016 16:37:45 by m2html © 2005