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