PageRenderTime 58ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/examples/toolboxes/eeglab/functions/sigprocfunc/topoplot.m

http://brainstream.googlecode.com/
MATLAB | 1796 lines | 806 code | 59 blank | 931 comment | 169 complexity | 63b3e4e8617f20a82e9eb7717c7afa10 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.0, GPL-3.0, GPL-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  1. % topoplot() - plot a topographic map of a scalp data field in a 2-D circular view
  2. % (looking down at the top of the head) using interpolation on a fine
  3. % cartesian grid. Can also show specified channnel location(s), or return
  4. % an interpolated value at an arbitrary scalp location (see 'noplot').
  5. % By default, channel locations below head center (arc_length 0.5) are
  6. % shown in a 'skirt' outside the cartoon head (see 'plotrad' and 'headrad'
  7. % options below). Nose is at top of plot; left is left; right is right.
  8. % Using option 'plotgrid', the plot may be one or more rectangular grids.
  9. % Usage:
  10. % >> topoplot(datavector, EEG.chanlocs); % plot a map using an EEG chanlocs structure
  11. % >> topoplot(datavector, 'my_chan.locs'); % read a channel locations file and plot a map
  12. % >> topoplot('example'); % give an example of an electrode location file
  13. % >> [h grid_or_val plotrad_or_grid, xmesh, ymesh]= ...
  14. % topoplot(datavector, chan_locs, 'Input1','Value1', ...);
  15. % Required Inputs:
  16. % datavector - single vector of channel values. Else, if a vector of selected subset
  17. % (int) channel numbers -> mark their location(s) using 'style' 'blank'.
  18. % chan_locs - name of an EEG electrode position file (>> topoplot example).
  19. % Else, an EEG.chanlocs structure (>> help readlocs or >> topoplot example)
  20. % Optional inputs:
  21. % 'maplimits' - 'absmax' -> scale map colors to +/- the absolute-max (makes green 0);
  22. % 'maxmin' -> scale colors to the data range (makes green mid-range);
  23. % [lo.hi] -> use user-definined lo/hi limits
  24. % {default: 'absmax'}
  25. % 'style' - 'map' -> plot colored map only
  26. % 'contour' -> plot contour lines only
  27. % 'both' -> plot both colored map and contour lines
  28. % 'fill' -> plot constant color between contour lines
  29. % 'blank' -> plot electrode locations only {default: 'both'}
  30. % 'electrodes' - 'on','off','labels','numbers','ptslabels','ptsnumbers'. To set the 'pts'
  31. % marker,,see 'Plot detail options' below. {default: 'on' -> mark electrode
  32. % locations with points ('.') unless more than 64 channels, then 'off'}.
  33. % 'plotchans' - [vector] channel numbers (indices) to use in making the head plot.
  34. % {default: [] -> plot all chans}
  35. % 'chantype' - cell array of channel type(s) to plot. Will also accept a single quoted
  36. % string type. Channel type for channel k is field EEG.chanlocs(k).type.
  37. % If present, overrides 'plotchans' and also 'chaninfo' with field
  38. % 'chantype'. Ex. 'EEG' or {'EEG','EOG'} {default: all, or 'plotchans' arg}
  39. % 'plotgrid' - [channels] Plot channel data in one or more rectangular grids, as
  40. % specified by [channels], a position matrix of channel numbers defining
  41. % the topographic locations of the channels in the grid. Zero values are
  42. % given the figure background color; negative integers, the color of the
  43. % polarity-reversed channel values. Ex: >> figure; ...
  44. % >> topoplot(values,'chanlocs','plotgrid',[11 12 0; 13 14 15]);
  45. % % Plot a (2,3) grid of data values from channels 11-15 with one empty
  46. % grid cell (top right) {default: no grid plot}
  47. % 'nosedir' - ['+X'|'-X'|'+Y'|'-Y'] direction of nose {default: '+X'}
  48. % 'chaninfo' - [struct] optional structure containing fields 'nosedir', 'plotrad'
  49. % and/or 'chantype'. See these (separate) field definitions above, below.
  50. % {default: nosedir +X, plotrad 0.5, all channels}
  51. % 'plotrad' - [0.15<=float<=1.0] plotting radius = max channel arc_length to plot.
  52. % See >> topoplot example. If plotrad > 0.5, chans with arc_length > 0.5
  53. % (i.e. below ears-eyes) are plotted in a circular 'skirt' outside the
  54. % cartoon head. See 'intrad' below. {default: max(max(chanlocs.radius),0.5);
  55. % If the chanlocs structure includes a field chanlocs.plotrad, its value
  56. % is used by default}.
  57. % 'headrad' - [0.15<=float<=1.0] drawing radius (arc_length) for the cartoon head.
  58. % NOTE: Only headrad = 0.5 is anatomically correct! 0 -> don't draw head;
  59. % 'rim' -> show cartoon head at outer edge of the plot {default: 0.5}
  60. % 'intrad' - [0.15<=float<=1.0] radius of the scalp map interpolation area (square or
  61. % disk, see 'intsquare' below). Interpolate electrodes in this area and use
  62. % this limit to define boundaries of the scalp map interpolated data matrix
  63. % {default: max channel location radius}
  64. % 'intsquare' - ['on'|'off'] 'on' -> Interpolate values at electrodes located in the whole
  65. % square containing the (radius intrad) interpolation disk; 'off' -> Interpolate
  66. % values from electrodes shown in the interpolation disk only {default: 'on'}.
  67. % 'conv' - ['on'|'off'] Show map interpolation only out to the convext hull of
  68. % the electrode locations to minimize extrapolation. {default: 'off'}
  69. % 'noplot' - ['on'|'off'|[rad theta]] do not plot (but return interpolated data).
  70. % Else, if [rad theta] are coordinates of a (possibly missing) channel,
  71. % returns interpolated value for channel location. For more info,
  72. % see >> topoplot 'example' {default: 'off'}
  73. % 'verbose' - ['on'|'off'] comment on operations on command line {default: 'on'}.
  74. %
  75. % Plot detail options:
  76. % 'drawaxis' - ['on'|'off'] draw axis on the top left corner.
  77. % 'emarker' - Matlab marker char | {markerchar color size linewidth} char, else cell array
  78. % specifying the electrode 'pts' marker. Ex: {'s','r',32,1} -> 32-point solid
  79. % red square. {default: {'.','k',[],1} where marker size ([]) depends on the number
  80. % of channels plotted}.
  81. % 'emarker2' - {markchans}|{markchans marker color size linewidth} cell array specifying
  82. % an alternate marker for specified 'plotchans'. Ex: {[3 17],'s','g'}
  83. % {default: none, or if {markchans} only are specified, then {markchans,'o','r',10,1}}
  84. % 'hcolor' - color of the cartoon head. Use 'hcolor','none' to plot no head. {default: 'k' = black}
  85. % 'shading' - 'flat','interp' {default: 'flat'}
  86. % 'numcontour' - number of contour lines {default: 6}
  87. % 'color' - color of the contours {default: dark grey}
  88. % 'whitebk ' - ('on'|'off') make the background color white (e.g., to print empty plotgrid channels)
  89. % {default: 'off'}
  90. % 'gridscale' - [int > 32] size (nrows) of interpolated scalp map data matrix {default: 67}
  91. % 'colormap' - (n,3) any size colormap {default: existing colormap}
  92. % 'circgrid' - [int > 100] number of elements (angles) in head and border circles {201}
  93. %
  94. % Dipole plotting options:
  95. % 'dipole' - [xi yi xe ye ze] plot dipole on the top of the scalp map
  96. % from coordinate (xi,yi) to coordinates (xe,ye,ze) (dipole head
  97. % model has radius 1). If several rows, plot one dipole per row.
  98. % Coordinates returned by dipplot() may be used. Can accept
  99. % an EEG.dipfit.model structure (See >> help dipplot).
  100. % Ex: ,'dipole',EEG.dipfit.model(17) % Plot dipole(s) for comp. 17.
  101. % 'dipnorm' - ['on'|'off'] normalize dipole length {default: 'on'}.
  102. % 'diporient' - [-1|1] invert dipole orientation {default: 1}.
  103. % 'diplen' - [real] scale dipole length {default: 1}.
  104. % 'dipscale' - [real] scale dipole size {default: 1}.
  105. % 'dipsphere' - [real] size of the dipole sphere. {default: 85 mm}.
  106. % 'dipcolor' - [color] dipole color as Matlab code code or [r g b] vector
  107. % {default: 'k' = black}.
  108. % Outputs:
  109. % h - plot axes handle
  110. % grid_or_val - [matrix] the interpolated data image (with off-head points = NaN).
  111. % Else, single interpolated value at the specified 'noplot' arg channel
  112. % location ([rad theta]), if any.
  113. % plotrad_or_grid - IF grid image returned above, then the 'plotrad' radius of the grid.
  114. % Else, the grid image
  115. % xmesh, ymesh - x and y values of the returned grid (above)
  116. %
  117. % Chan_locs format:
  118. % See >> topoplot 'example'
  119. %
  120. % Examples:
  121. %
  122. % To plot channel locations only:
  123. % >> figure; topoplot([],EEG.chanlocs,'style','blank','electrodes','labelpoint','chaninfo',EEG.chaninfo);
  124. %
  125. % Notes: - To change the plot map masking ring to a new figure background color,
  126. % >> set(findobj(gca,'type','patch'),'facecolor',get(gcf,'color'))
  127. % - Topoplots may be rotated. From the commandline >> view([deg 90]) {default: [0 90])
  128. %
  129. % Authors: Andy Spydell, Colin Humphries, Arnaud Delorme & Scott Makeig
  130. % CNL / Salk Institute, 8/1996-/10/2001; SCCN/INC/UCSD, Nov. 2001 -
  131. %
  132. % See also: timtopo(), envtopo()
  133. % Deprecated options:
  134. % 'shrink' - ['on'|'off'|'force'|factor] Deprecated. 'on' -> If max channel arc_length
  135. % > 0.5, shrink electrode coordinates towards vertex to plot all channels
  136. % by making max arc_length 0.5. 'force' -> Normalize arc_length
  137. % so the channel max is 0.5. factor -> Apply a specified shrink
  138. % factor (range (0,1) = shrink fraction). {default: 'off'}
  139. % 'electcolor' {'k'} ... electrode marking details and their {defaults}.
  140. % 'emarker' {'.'}|'emarkersize' {14}|'emarkersizemark' {40}|'efontsize' {var} -
  141. % electrode marking details and their {defaults}.
  142. % 'ecolor' - color of the electrode markers {default: 'k' = black}
  143. % 'interplimits' - ['electrodes'|'head'] 'electrodes'-> interpolate the electrode grid;
  144. % 'head'-> interpolate the whole disk {default: 'head'}.
  145. % Unimplemented future options:
  146. % Copyright (C) Colin Humphries & Scott Makeig, CNL / Salk Institute, Aug, 1996
  147. %
  148. % This program is free software; you can redistribute it and/or modify
  149. % it under the terms of the GNU General Public License as published by
  150. % the Free Software Foundation; either version 2 of the License, or
  151. % (at your option) any later version.
  152. %
  153. % This program is distributed in the hope that it will be useful,
  154. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  155. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  156. % GNU General Public License for more details.
  157. %
  158. % You should have received a copy of the GNU General Public License
  159. % along with this program; if not, write to the Free Software
  160. % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  161. % $Log: topoplot.m,v $
  162. % Revision 1.284 2008/04/19 21:01:34 arno
  163. % fix 'example'.
  164. %
  165. % Revision 1.283 2008/01/10 01:24:55 nima
  166. % dipole direction line problem fixed.
  167. %
  168. % Revision 1.282 2007/11/29 17:49:56 arno
  169. % header typo
  170. %
  171. % Revision 1.281 2007/09/11 10:57:53 arno
  172. % catch error when plotting channels outside bounadries
  173. %
  174. % Revision 1.280 2007/08/08 17:50:55 arno
  175. % fix typo
  176. %
  177. % Revision 1.279 2007/08/08 17:38:13 arno
  178. % handle better fieldtrip
  179. %
  180. % Revision 1.278 2007/08/07 21:33:01 arno
  181. % remove debug message
  182. %
  183. % Revision 1.277 2007/08/07 21:22:34 arno
  184. % changed optional arguments to use varargin, call topoplot from fieldtrip if necessary
  185. %
  186. % Revision 1.276 2007/02/05 20:25:58 toby
  187. % fixed bug when entering channels to plot instead of channel values as the first Input
  188. %
  189. % Revision 1.275 2006/09/14 09:31:43 arno
  190. % fix the white background command
  191. %
  192. % Revision 1.274 2006/07/21 03:05:34 toby
  193. % *** empty log message ***
  194. %
  195. % Revision 1.273 2006/07/21 02:44:48 toby
  196. % commented out faulty error message
  197. %
  198. % Revision 1.272 2006/05/07 18:10:15 arno
  199. % channels indices were not accurate -> fixing them
  200. %
  201. % Revision 1.271 2006/04/12 02:54:13 toby
  202. % help text edit
  203. %
  204. % Revision 1.270 2006/03/13 22:44:32 arno
  205. % change default marker
  206. %
  207. % Revision 1.269 2006/03/09 17:15:37 arno
  208. % change default marker size
  209. % /
  210. %
  211. % Revision 1.268 2006/01/17 23:01:27 scott
  212. % clarified status of 'plotgrid' -sm
  213. %
  214. % Revision 1.267 2005/12/08 00:22:19 arno
  215. % fixing ploting one channel
  216. %
  217. % Revision 1.266 2005/12/01 20:28:29 arno
  218. % typo
  219. %
  220. % Revision 1.265 2005/11/30 19:07:58 arno
  221. % fixing ploting electrodes only
  222. %
  223. % Revision 1.264 2005/11/30 19:02:40 arno
  224. % generic plotchan
  225. %
  226. % Revision 1.263 2005/11/21 21:30:08 toby
  227. % Corrected a crash-error when attempting to use "plotgrid" and "maplimit>absmax" options
  228. %
  229. % Revision 1.262 2005/11/11 00:58:03 arno
  230. % nothing
  231. %
  232. % Revision 1.261 2005/10/29 03:57:01 scott
  233. % chantype help
  234. %
  235. % Revision 1.260 2005/10/27 22:00:26 toby
  236. % adding channel type
  237. %
  238. % Revision 1.258 2005/09/29 14:56:41 scott
  239. % nothing
  240. %
  241. % Revision 1.257 2005/09/27 21:59:49 arno
  242. % fix plotrad issue call from pop_chanedit
  243. %
  244. % Revision 1.256 2005/09/05 15:58:14 scott
  245. % nothing - spacing while looking through code -sm
  246. %
  247. % Revision 1.255 2005/07/27 18:12:59 arno
  248. % removing datachan check
  249. %
  250. % Revision 1.254 2005/07/16 16:36:08 scott
  251. % same
  252. %
  253. % Revision 1.253 2005/07/16 16:27:25 scott
  254. % fixed 'maplimits',[min max] execution, added test -sm
  255. %
  256. % Revision 1.252 2005/07/12 17:03:25 scott
  257. % documented 'whitebk' option -sm
  258. %
  259. % Revision 1.251 2005/06/09 23:33:46 arno
  260. % remove getdatachan function
  261. %
  262. % Revision 1.250 2005/06/09 23:33:21 arno
  263. % fixing datachan
  264. %
  265. % Revision 1.249 2005/06/09 16:36:25 arno
  266. % getdatachans
  267. %
  268. % Revision 1.248 2005/03/09 17:08:03 arno
  269. % implementing nosedir
  270. %
  271. % Revision 1.247 2005/03/07 17:11:19 arno
  272. % implement chaninfo
  273. %
  274. % Revision 1.246 2005/01/28 17:26:10 arno
  275. % fix typo
  276. %
  277. % Revision 1.245 2005/01/25 18:47:01 scott
  278. % fixed recent bug that made all topoplot colors positive!!
  279. % worked on bug when removing gridchans from specified plotchans (using setxor)
  280. %
  281. % Revision 1.244 2005/01/25 01:32:53 scott
  282. % help msg
  283. %
  284. % Revision 1.243 2005/01/10 20:26:34 scott
  285. % adjust color limits for 'gridplot'
  286. %
  287. % Revision 1.242 2005/01/10 19:46:47 scott
  288. % added (undoc) arg 'whitebk'
  289. %
  290. % Revision 1.241 2005/01/07 22:39:40 scott
  291. % fixed 'labelpoint' keyword for 'electrodes' (used in eeglab.m)
  292. %
  293. % Revision 1.240 2005/01/07 19:55:47 scott
  294. % remove traces of 'gridpos'
  295. %
  296. % Revision 1.239 2005/01/06 19:27:17 scott
  297. % implemented 'gridplot' | 'plotgrid' option
  298. %
  299. % Revision 1.238 2005/01/03 02:27:32 scott
  300. % made 'grid' rectangular (each element square)
  301. %
  302. % Revision 1.237 2005/01/03 02:10:33 scott
  303. % added 'gridplot' option
  304. %
  305. % Revision 1.236 2005/01/02 18:42:25 scott
  306. % implementing 'plotgrid'
  307. %
  308. % Revision 1.235 2004/12/26 05:48:57 scott
  309. % enlarged definition of 'emarker', deprecated 'ecolor','emarkersize'...
  310. %
  311. % Revision 1.234 2004/12/24 19:48:23 scott
  312. % fixed and extended 'emarker2' args; added 'hcolor','none' option; changed 'emarkersize1chan' to
  313. % 'emarkersizemark' (preserving backwards compatability as well). tested with /home/www/eeglab/test_topoplot.m
  314. %
  315. % Revision 1.233 2004/12/24 01:32:29 scott
  316. % documented xmesh, ymesh optional outputs
  317. %
  318. % Revision 1.232 2004/12/24 01:25:28 scott
  319. % clarified 'plotchans', added 'emarker2'
  320. %
  321. % Revision 1.231 2004/12/21 23:18:48 hilit
  322. % change x and y axis to depend on squeezfac, in case 'intrad' is provided
  323. %
  324. % Revision 1.230 2004/12/20 22:05:44 scott
  325. % if intrad specified, then make plotrad <= intrad
  326. %
  327. % Revision 1.229 2004/12/20 21:13:41 scott
  328. % made specifying 'intrad' -> actually use intrad to define the interp grid.
  329. % returned Xi, Yi for toporeplot() (undocumented)
  330. %
  331. % Revision 1.228 2004/12/17 16:36:53 scott
  332. % cleaning up 'plotgrid' code
  333. %
  334. % Revision 1.227 2004/12/17 06:49:57 scott
  335. % tested if isstruct or string chan_loc; worked on plotgrid - still unimplemented
  336. %
  337. % Revision 1.226 2004/12/10 21:00:17 scott
  338. % made 3rd output plotrad (by default). Documented reading of chanlocs.plotrad
  339. % if it exists.
  340. %
  341. % Revision 1.225 2004/11/23 01:52:12 hilit
  342. % fixing 'style' 'blank' problems
  343. %
  344. % Revision 1.224 2004/11/22 21:55:46 hilit
  345. % undo some of the changes
  346. %
  347. % Revision 1.223 2004/11/22 21:47:14 hilit
  348. % debugging 'style' 'blank' problems
  349. %
  350. % Revision 1.222 2004/11/22 20:11:38 scott
  351. % trying to fix style 'blank' problems
  352. %
  353. % Revision 1.221 2004/11/22 05:41:43 arno
  354. % more debugging
  355. %
  356. % Revision 1.220 2004/11/22 05:39:05 arno
  357. % function was crashing on regular topoplot, debuging
  358. %
  359. % Revision 1.219 2004/11/22 05:02:51 scott
  360. % fixing topoplot([],EEG.chanlocs,'emarker','o')
  361. %
  362. % Revision 1.218 2004/11/22 04:58:21 scott
  363. % fixed topoplot(32,EEG.chanlocs) and topoplot([],EEG.chanlocs,'emarker','o')
  364. % to plot marked channel 32 in red disk
  365. %
  366. % Revision 1.217 2004/11/18 20:29:14 hilit
  367. % enabled the 'example' option
  368. %
  369. % Revision 1.216 2004/11/18 19:22:22 scott
  370. % made 3rd output, 'grid'. [] unless interpolated value asked for
  371. %
  372. % Revision 1.215 2004/11/09 19:25:08 arno
  373. % move plotgrid help outsie of header since unimplemented
  374. %
  375. % Revision 1.214 2004/10/27 17:34:35 scott
  376. % help msg adjust -sm
  377. %
  378. % Revision 1.213 2004/10/27 16:39:06 arno
  379. % remove infinite and NaN values
  380. %
  381. % Revision 1.212 2004/10/09 22:26:18 scott
  382. % iv interp. value output, then output grid too -sm
  383. %
  384. % Revision 1.211 2004/10/08 21:34:25 scott
  385. % same -sm
  386. %
  387. % Revision 1.210 2004/10/08 21:32:09 scott
  388. % help message clarification on outputs -sm
  389. %
  390. % Revision 1.209 2004/10/07 15:55:15 scott
  391. % made Values==[] work with plotchans -sm
  392. %
  393. % Revision 1.208 2004/09/29 15:44:46 scott
  394. % added 'plotchans' option. upgraded 'plotgrid' (still unimplemented) -sm
  395. %
  396. % Revision 1.207 2004/09/29 01:04:22 scott
  397. % created input 'plotgrid' - plotting not yet implemented -sm
  398. %
  399. % Revision 1.206 2004/09/10 00:53:08 hilit
  400. % converted input arguments to text() to double
  401. %
  402. % Revision 1.205 2004/07/07 22:21:30 arno
  403. % debug shrink
  404. %
  405. % Revision 1.204 2004/06/10 19:11:53 arno
  406. % remove debug msg
  407. %
  408. % Revision 1.203 2004/05/14 23:41:09 arno
  409. % allowing negative shrink
  410. %
  411. % Revision 1.202 2004/05/14 23:29:32 arno
  412. % fixing toggle name/number
  413. %
  414. % Revision 1.201 2004/05/10 15:14:34 scott
  415. % more flexible labels/numbers/points argument reading; defined ELECTRODE_HEIGHT
  416. %
  417. % Revision 1.200 2004/05/07 15:12:51 scott
  418. % removed textax, instead plot3() electrode labels/pts/numbers above the rest with plot3() -sm
  419. %
  420. % Revision 1.199 2004/05/07 04:35:10 scott
  421. % superimpose textax again - making both axes square
  422. %
  423. % Revision 1.198 2004/05/05 21:57:23 hilit
  424. % removed text from the previous log message
  425. %
  426. % Revision 1.197 2004/05/05 20:56:20 hilit
  427. % change the defult setting of dipnorm to 'on'.
  428. %
  429. % Revision 1.197 2004/05/05 13:55:00 hilit
  430. % Set the defult option of dipnorm to 'on'
  431. %
  432. % Revision 1.196 2004/05/05 20:36:04 scott
  433. % DIPOLE scaling
  434. %
  435. % Revision 1.195 2004/05/05 20:21:02 scott
  436. % *** empty log message ***
  437. %
  438. % Revision 1.194 2004/04/29 18:58:48 scott
  439. % removed new axes - scaling problem. Toggling pts|numbers doesnt work inside head cartoon.
  440. %
  441. % Revision 1.193 2004/04/29 18:36:46 scott
  442. % test
  443. %
  444. % Revision 1.192 2004/04/29 18:23:03 scott
  445. % make overplot axis limits the same as topoplot limits
  446. %
  447. % Revision 1.191 2004/04/28 18:19:06 scott
  448. % put labels/numbers on another axes so that clicking numbers<->labels
  449. % will work inside the head cartoon patch
  450. %
  451. % Revision 1.190 2004/04/28 17:00:42 scott
  452. % no blanking ring when style is 'blank'
  453. %
  454. % Revision 1.189 2004/04/01 17:10:46 scott
  455. % converted 'conv' interpolation to polar
  456. %
  457. % Revision 1.188 2004/03/31 18:23:15 scott
  458. % debug 'conv' mode - plot ears and nose above map surface to avoid masking by 'conv'
  459. %
  460. % Revision 1.187 2004/03/31 18:06:53 scott
  461. % adding 'conv' mode for plotting convex hull; corrected shrink in 'interp' mode
  462. %
  463. % Revision 1.186 2004/03/31 05:15:05 scott
  464. % *** empty log message ***
  465. %
  466. % Revision 1.185 2004/03/31 05:06:27 scott
  467. % implementing 'conv' (undocumented)
  468. %
  469. % Revision 1.184 2004/03/31 03:19:02 scott
  470. % adjust ear lines
  471. %
  472. % Revision 1.183 2004/03/31 02:53:35 scott
  473. % made blanking ring and head filled rings; made default electrodes 'off' iff chans>64; made contour color
  474. % dark grey; adjusted nose and ear shapes
  475. %
  476. % Revision 1.182 2004/03/31 02:08:07 scott
  477. % *** empty log message ***
  478. %
  479. % Revision 1.181 2004/03/30 18:48:21 scott
  480. % same
  481. %
  482. % Revision 1.180 2004/03/30 18:29:08 scott
  483. % testing fill ring
  484. %
  485. % Revision 1.179 2004/03/30 17:38:15 scott
  486. % plot ring patch instead of blanking circle
  487. %
  488. % Revision 1.178 2004/03/25 22:30:13 arno
  489. % same thing
  490. %
  491. % Revision 1.177 2004/03/25 22:26:45 arno
  492. % same thing
  493. %
  494. % Revision 1.176 2004/03/25 22:24:41 arno
  495. % fixing shrinkfactor bug
  496. %
  497. % Revision 1.175 2004/03/24 16:35:25 scott
  498. % added 'cricgrid' plotting detail argument
  499. %
  500. % Revision 1.174 2004/03/23 19:19:34 scott
  501. % made 'electrodes' default 'off'
  502. %
  503. % Revision 1.173 2004/03/23 19:18:32 scott
  504. % default: plotrad >= 0.5
  505. %
  506. % Revision 1.172 2004/03/23 15:20:39 scott
  507. % made only 2 outputs
  508. %
  509. % Revision 1.171 2004/03/23 00:40:06 scott
  510. % clarifying handling of un-located channels
  511. %
  512. % Revision 1.170 2004/03/22 17:57:21 scott
  513. % added arg 'intrad' - separated interpolation and plotting areas
  514. % Now, by default, interpolates over all the (radius<=1) electrodes.
  515. % Added 'intsquare' option - interpolated values in electrodes in the entire
  516. % interpolation square, not just the (plotting) disk. Can give more accurate
  517. % interpolation at edges of the plotting disk i.e. interpolation instead of
  518. % extrapolation), if there are additional channel locations beyond the plotting area
  519. %
  520. % Revision 1.169 2004/03/22 03:25:41 scott
  521. % re-implmenting shrink options
  522. %
  523. % Revision 1.168 2004/03/21 19:19:18 scott
  524. % help message
  525. %
  526. % Revision 1.167 2004/03/21 18:02:08 scott
  527. % debugged deprecated 'shrink' mode code
  528. %
  529. % Revision 1.166 2004/03/21 17:31:44 scott
  530. % nothing
  531. %
  532. % Revision 1.165 2004/03/21 17:25:39 scott
  533. % corrected dipole plotting
  534. %
  535. % Revision 1.164 2004/03/21 16:52:37 scott
  536. % debugged plotrad, headrad plot size setting
  537. %
  538. % Revision 1.163 2004/03/20 18:20:14 scott
  539. % created 'headrad' (removed 'forcehead'). Now uses only 'plotrad' and 'headrad'
  540. % to set plotting scales. 'shrink' mode disabled temporarily
  541. %
  542. % Revision 1.162 2004/03/19 21:57:58 scott
  543. % do not plot channels with arc_length > 1
  544. %
  545. % Revision 1.161 2004/03/19 19:47:13 arno
  546. % remove str2num
  547. %
  548. % Revision 1.160 2004/03/19 19:05:26 scott
  549. % read string plotrad from channel locations structure
  550. %
  551. % Revision 1.159 2004/03/19 17:46:19 scott
  552. % added 'forcehead'; changed 'pointnumbers' and 'pointlabels' to 'ptnumbers', 'ptlabels'
  553. % but kept backwards compatibility. Allowed marking of multiple channel locations
  554. % without requiring an explicit 'style','blank'. Allowed [] data -> plot channel
  555. % locations. Improved help message and 'example' text. Switched order of plotting
  556. % of head border, electrodes and head cartoon. Made head cartoon not appear by
  557. % default when plotrad<0.5 or 'shrink' is severe (but see 'forcehead'). -sm
  558. %
  559. % Revision 1.158 2004/03/19 02:33:40 scott
  560. % plotting head, ears and/or skirt as appropriate from plotrad and shrink args
  561. %
  562. % Revision 1.157 2004/03/19 01:49:07 scott
  563. % plotrad
  564. %
  565. % Revision 1.156 2004/03/19 00:30:08 scott
  566. % plotrad minmax
  567. %
  568. % Revision 1.155 2004/03/18 17:05:20 arno
  569. % fixed plotrad
  570. %
  571. % Revision 1.154 2004/03/18 16:36:53 arno
  572. % debug shrink and plotrad
  573. %
  574. % Revision 1.153 2004/03/18 16:22:12 arno
  575. % debug shrink
  576. %
  577. % Revision 1.152 2004/03/18 01:47:24 scott
  578. % debug
  579. %
  580. % Revision 1.151 2004/03/18 01:44:28 scott
  581. % 'plotrad' arg and help message re skirt
  582. %
  583. % Revision 1.150 2004/03/18 01:26:33 arno
  584. % plotrad
  585. %
  586. % Revision 1.149 2004/03/18 00:29:07 arno
  587. % debug skirt option
  588. %
  589. % Revision 1.148 2004/03/18 00:18:09 arno
  590. % skirt option
  591. %
  592. % Revision 1.147 2004/02/25 15:29:39 scott
  593. % dont plot border if shrinkfac < .01
  594. %
  595. % Revision 1.146 2004/02/25 15:25:07 scott
  596. % adjust border of 'skirt'
  597. %
  598. % Revision 1.145 2004/02/25 15:19:38 scott
  599. % not allowing shrink to be negative
  600. %
  601. % Revision 1.144 2004/02/23 16:55:51 scott
  602. % don't let ears go outside axes if shrink is 'skirt' but shrink factor is 0 or small
  603. %
  604. % Revision 1.143 2004/02/19 15:56:28 scott
  605. % plot dipole(s) last
  606. %
  607. % Revision 1.142 2004/02/19 15:49:58 scott
  608. % plot dipoles inside head in 'skirt' mode
  609. %
  610. % Revision 1.141 2004/02/18 01:16:53 scott
  611. % help message adjust
  612. %
  613. % Revision 1.140 2004/02/18 01:02:58 scott
  614. % 'dipole' help message. Adaptive AXHEADFAC.
  615. %
  616. % Revision 1.139 2004/02/17 22:44:54 arno
  617. % now processing DIPFIT structure and fixed normalization bug
  618. %
  619. % Revision 1.138 2004/02/17 18:16:35 scott
  620. % adjust EMARKERSIZE
  621. %
  622. % Revision 1.137 2004/02/17 18:11:36 scott
  623. % fixed 'skirt'&'fill' problem. Also, made heads bigger
  624. %
  625. % Revision 1.136 2004/02/17 16:58:24 scott
  626. % change color of outer 'shrink' mode ring to almost white, to avoid print bug
  627. %
  628. % Revision 1.135 2004/02/17 03:14:44 scott
  629. % expand skirt border radius
  630. %
  631. % Revision 1.134 2004/02/15 21:30:01 scott
  632. % same
  633. %
  634. % Revision 1.133 2004/02/15 21:17:07 scott
  635. % omit QUAD_SKIRT option - not ready !
  636. %
  637. % Revision 1.132 2004/02/15 21:02:13 scott
  638. % same
  639. % Revision 1.96 2004/02/15 19:41:48 scott
  640. % skirt with wedges
  641. %
  642. % Revision 1.95 2004/02/15 17:35:49 scott
  643. % added 'style','skirt'
  644. %
  645. % Revision 1.72 2004/02/15 15:58:33 scott
  646. % formatting, try 'shrink','skirt' ...
  647. %
  648. % Revision 1.71 2004/01/20 04:25:05 scott
  649. % help msg edit
  650. % .,
  651. %
  652. % Revision 1.70 2003/12/17 15:49:45 arno
  653. % debug chan with no coordinates
  654. %
  655. % Revision 1.69 2003/12/17 01:25:37 arno
  656. % debug plot electrode subset
  657. %
  658. % Revision 1.68 2003/12/17 00:57:17 arno
  659. % subset of electrodes
  660. %
  661. % Revision 1.67 2003/11/29 23:34:00 scott
  662. % help msg
  663. %
  664. % Revision 1.66 2003/11/06 16:31:18 arno
  665. % changing dipnorm
  666. %
  667. % Revision 1.65 2003/11/06 02:04:41 arno
  668. % correct orientation
  669. %
  670. % Revision 1.64 2003/11/06 01:40:31 arno
  671. % diporient
  672. %
  673. % Revision 1.63 2003/11/06 01:00:57 arno
  674. % adjusting corrdinates
  675. % for dipole
  676. %
  677. % Revision 1.62 2003/11/05 20:35:21 arno
  678. % dipole options
  679. %
  680. % Revision 1.61 2003/11/05 19:44:32 arno
  681. % header text
  682. %
  683. % Revision 1.60 2003/08/08 17:36:12 arno
  684. % shrink factor overwrite problem fixed
  685. %
  686. % Revision 1.59 2003/08/08 17:34:41 arno
  687. % -cos -> cos
  688. %
  689. % Revision 1.58 2003/08/07 20:49:12 arno
  690. % option 'masksurf' to speed up display
  691. %
  692. % Revision 1.57 2003/08/07 16:02:35 scott
  693. % typo
  694. %
  695. % Revision 1.56 2003/08/07 16:01:49 scott
  696. % debug
  697. %
  698. % Revision 1.55 2003/08/07 15:56:54 scott
  699. % debug
  700. %
  701. % Revision 1.54 2003/08/07 15:54:49 scott
  702. % debug last
  703. %
  704. % Revision 1.53 2003/08/07 15:51:05 scott
  705. % added 'noplot' option to return interpolated channel value
  706. %
  707. % Revision 1.52 2003/07/18 01:34:07 scott
  708. % text placement
  709. %
  710. % Revision 1.51 2003/07/18 01:33:19 scott
  711. % text placement
  712. %
  713. % Revision 1.50 2003/07/18 01:31:49 scott
  714. % debug
  715. %
  716. % Revision 1.49 2003/07/18 01:27:17 scott
  717. % debug
  718. %
  719. % Revision 1.48 2003/07/18 01:26:05 scott
  720. % debug
  721. %
  722. % Revision 1.47 2003/07/18 01:18:12 scott
  723. % debug last
  724. %
  725. % Revision 1.46 2003/07/18 01:17:34 scott
  726. % formatting, debug axes size message
  727. %
  728. % Revision 1.45 2003/07/17 23:42:32 scott
  729. % nothing
  730. %
  731. % Revision 1.44 2003/07/17 23:13:03 scott
  732. % rm debug message
  733. %
  734. % Revision 1.43 2003/07/16 16:29:46 arno
  735. % replacing with topoplottest - added image output, gridscale arg
  736. %
  737. % Revision 1.41 2003/07/15 23:55:40 arno
  738. % retreiving version 1.28
  739. %
  740. % Revision 1.28 2003/06/27 18:53:04 arno
  741. % header msg
  742. %
  743. % Revision 1.27 2003/05/12 22:27:44 arno
  744. % debug verbose
  745. %
  746. % Revision 1.26 2003/05/12 22:23:38 arno
  747. % adding verbose option
  748. %
  749. % Revision 1.25 2002/11/27 01:23:53 arno
  750. % change warning message
  751. %
  752. % Revision 1.24 2002/11/12 23:06:48 arno
  753. % still debugging last insert
  754. %
  755. % Revision 1.23 2002/11/12 22:19:01 arno
  756. % typo
  757. %
  758. % Revision 1.22 2002/11/12 21:43:51 scott
  759. % tmpelocs -> tmpeloc
  760. %
  761. % Revision 1.21 2002/11/12 19:33:24 arno
  762. % remove last channel of eloc structure if necessary (common ref)
  763. %
  764. % Revision 1.20 2002/11/01 03:50:08 erik
  765. % same
  766. %
  767. % Revision 1.19 2002/11/01 03:47:40 erik
  768. % added test for locs_file string to readlocs call
  769. %
  770. % Revision 1.18 2002/10/31 22:51:25 luca
  771. % now also plotting n < nchans single channels
  772. %
  773. % Revision 1.17 2002/10/30 18:50:37 arno
  774. % debugging dipole
  775. %
  776. % Revision 1.16 2002/10/30 16:41:21 arno
  777. % adding the dipole option
  778. %
  779. % Revision 1.15 2002/10/26 20:09:35 arno
  780. % error typo
  781. %
  782. % Revision 1.14 2002/10/14 00:40:44 arno
  783. % *** empty log message ***
  784. %
  785. % Revision 1.13 2002/09/23 18:09:11 arno
  786. % fixing single channel plotting
  787. %
  788. % Revision 1.12 2002/08/13 17:45:58 arno
  789. % undo last change
  790. %
  791. % Revision 1.11 2002/08/13 17:44:37 arno
  792. % remove color setting
  793. %
  794. % Revision 1.10 2002/08/12 01:34:53 arno
  795. % color
  796. %
  797. % Revision 1.9 2002/08/11 22:31:20 arno
  798. % color
  799. %
  800. % Revision 1.8 2002/05/01 18:49:20 arno
  801. % modifying default shrink
  802. %
  803. % Revision 1.7 2002/05/01 02:40:10 arno
  804. % typo
  805. %
  806. % Revision 1.6 2002/04/24 17:30:47 arno
  807. % auto shrink
  808. %
  809. % Revision 1.5 2002/04/24 17:07:28 arno
  810. % debugging error message problem
  811. %
  812. % Revision 1.4 2002/04/17 18:40:23 arno
  813. % display real electrode number
  814. %
  815. % Revision 1.3 2002/04/06 03:47:44 arno
  816. % adding emarkersize1chan input
  817. %
  818. % Revision 1.2 2002/04/06 03:37:24 arno
  819. % adding single channel vector input
  820. %
  821. % Revision 1.1 2002/04/05 17:36:45 jorn
  822. % Initial revision
  823. %
  824. % Topoplot Version 2.1
  825. % Early development history:
  826. % Begun by Andy Spydell and Scott Makeig, NHRC, 7-23-96
  827. % 8-96 Revised by Colin Humphries, CNL / Salk Institute, La Jolla CA
  828. % -changed surf command to imagesc (faster)
  829. % -can now handle arbitrary scaling of electrode distances
  830. % -can now handle non integer angles in chan_locs
  831. % 4-4-97 Revised again by Colin Humphries, reformatted by SM
  832. % -added parameters
  833. % -changed chan_locs format
  834. % 2-26-98 Revised by Colin
  835. % -changed image back to surface command
  836. % -added fill and blank styles
  837. % -removed extra background colormap entry (now use any colormap)
  838. % -added parameters for electrode colors and labels
  839. % -now each topoplot axes use the caxis command again.
  840. % -removed OUTPUT parameter
  841. % 3-11-98 changed default emarkersize, improve help msg -sm
  842. % 5-24-01 made default emarkersize vary with number of channels -sm
  843. % 01-25-02 reformated help & license, added link -ad
  844. % 03-15-02 added readlocs and the use of eloc input structure -ad
  845. % 03-25-02 added 'labelpoint' options and allow Values=[] -ad &sm
  846. % 03-25-02 added details to "Unknown parameter" warning -sm & ad
  847. function [handle,Zi,grid,Xi,Yi] = topoplot(Values,loc_file,varargin)
  848. %
  849. %%%%%%%%%%%%%%%%%%%%%%%% Set defaults %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  850. %
  851. icadefs % read defaults MAXTOPOPLOTCHANS and DEFAULT_ELOC and BACKCOLOR
  852. if ~exist('BACKCOLOR') % if icadefs.m does not define BACKCOLOR
  853. BACKCOLOR = [.93 .96 1]; % EEGLAB standard
  854. end
  855. whitebk = 'off'; % by default, make gridplot background color = EEGLAB screen background color
  856. plotgrid = 'off';
  857. plotchans = [];
  858. noplot = 'off';
  859. handle = [];
  860. Zi = [];
  861. chanval = NaN;
  862. rmax = 0.5; % actual head radius - Don't change this!
  863. INTERPLIMITS = 'head'; % head, electrodes
  864. INTSQUARE = 'on'; % default, interpolate electrodes located though the whole square containing
  865. % the plotting disk
  866. default_intrad = 1; % indicator for (no) specified intrad
  867. MAPLIMITS = 'absmax'; % absmax, maxmin, [values]
  868. GRID_SCALE = 67; % plot map on a 67X67 grid
  869. CIRCGRID = 201; % number of angles to use in drawing circles
  870. AXHEADFAC = 1.3; % head to axes scaling factor
  871. CONTOURNUM = 6; % number of contour levels to plot
  872. STYLE = 'both'; % default 'style': both,straight,fill,contour,blank
  873. HEADCOLOR = [0 0 0]; % default head color (black)
  874. CCOLOR = [0.2 0.2 0.2]; % default contour color
  875. ELECTRODES = []; % default 'electrodes': on|off|label - set below
  876. MAXDEFAULTSHOWLOCS = 64;% if more channels than this, don't show electrode locations by default
  877. EMARKER = '.'; % mark electrode locations with small disks
  878. ECOLOR = [0 0 0]; % default electrode color = black
  879. EMARKERSIZE = []; % default depends on number of electrodes, set in code
  880. EMARKERLINEWIDTH = 1; % default edge linewidth for emarkers
  881. EMARKERSIZE1CHAN = 40; % default selected channel location marker size
  882. EMARKERCOLOR1CHAN = 'red'; % selected channel location marker color
  883. EMARKER2CHANS = []; % mark subset of electrode locations with small disks
  884. EMARKER2 = 'o'; % mark subset of electrode locations with small disks
  885. EMARKER2COLOR = 'r'; % mark subset of electrode locations with small disks
  886. EMARKERSIZE2 = 10; % default selected channel location marker size
  887. EMARKER2LINEWIDTH = 1;
  888. EFSIZE = get(0,'DefaultAxesFontSize'); % use current default fontsize for electrode labels
  889. HLINEWIDTH = 1.7; % default linewidth for head, nose, ears
  890. BLANKINGRINGWIDTH = .035;% width of the blanking ring
  891. HEADRINGWIDTH = .007;% width of the cartoon head ring
  892. SHADING = 'flat'; % default 'shading': flat|interp
  893. shrinkfactor = []; % shrink mode (dprecated)
  894. intrad = []; % default interpolation square is to outermost electrode (<=1.0)
  895. plotrad = []; % plotting radius ([] = auto, based on outermost channel location)
  896. headrad = []; % default plotting radius for cartoon head is 0.5
  897. squeezefac = 1.0;
  898. MINPLOTRAD = 0.15; % can't make a topoplot with smaller plotrad (contours fail)
  899. VERBOSE = 'off';
  900. MASKSURF = 'off';
  901. CONVHULL = 'off'; % dont mask outside the electrodes convex hull
  902. DRAWAXIS = 'off';
  903. CHOOSECHANTYPE = 0;
  904. %%%%%% Dipole defaults %%%%%%%%%%%%
  905. DIPOLE = [];
  906. DIPNORM = 'on';
  907. DIPSPHERE = 85;
  908. DIPLEN = 1;
  909. DIPSCALE = 1;
  910. DIPORIENT = 1;
  911. DIPCOLOR = [0 0 0];
  912. NOSEDIR = '+X';
  913. CHANINFO = [];
  914. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  915. %
  916. %%%%%%%%%%%%%%%%%%%%%%% Handle arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  917. %
  918. if nargin< 1
  919. help topoplot;
  920. return
  921. end
  922. % calling topoplot from Fieldtrip
  923. % -------------------------------
  924. fieldtrip = 0;
  925. if nargin < 2, loc_file = []; end;
  926. if isstruct(Values) | ~isstruct(loc_file), fieldtrip == 1; end;
  927. if isstr(loc_file), if exist(loc_file) ~= 2, fieldtrip == 1; end; end;
  928. if fieldtrip
  929. disp('Calling topoplot from Fieldtrip');
  930. dir1 = which('topoplot'); dir1 = fileparts(dir1);
  931. dir2 = which('electrodenormalize'); dir2 = fileparts(dir2);
  932. addpath(dir2);
  933. try,
  934. topoplot(Values, loc_file, varargin{:});
  935. catch,
  936. end;
  937. addpath(dir1);
  938. return;
  939. end;
  940. nargs = nargin;
  941. if nargs == 1
  942. if isstr(Values)
  943. if any(strcmp(lower(Values),{'example','demo'}))
  944. fprintf(['This is an example of an electrode location file,\n',...
  945. 'an ascii file consisting of the following four columns:\n',...
  946. ' channel_number degrees arc_length channel_name\n\n',...
  947. 'Example:\n',...
  948. ' 1 -18 .352 Fp1 \n',...
  949. ' 2 18 .352 Fp2 \n',...
  950. ' 5 -90 .181 C3 \n',...
  951. ' 6 90 .181 C4 \n',...
  952. ' 7 -90 .500 A1 \n',...
  953. ' 8 90 .500 A2 \n',...
  954. ' 9 -142 .231 P3 \n',...
  955. '10 142 .231 P4 \n',...
  956. '11 0 .181 Fz \n',...
  957. '12 0 0 Cz \n',...
  958. '13 180 .181 Pz \n\n',...
  959. ...
  960. 'In topoplot() coordinates, 0 deg. points to the nose, positive\n',...
  961. 'angles point to the right hemisphere, and negative to the left.\n',...
  962. 'The model head sphere has a circumference of 2; the vertex\n',...
  963. '(Cz) has arc_length 0. Locations with arc_length > 0.5 are below\n',...
  964. 'head center and are plotted outside the head cartoon.\n'....
  965. 'Option plotrad controls how much of this lower-head "skirt" is shown.\n',...
  966. 'Option headrad controls if and where the cartoon head will be drawn.\n',...
  967. 'Option intrad controls how many channels will be included in the interpolation.\n',...
  968. ])
  969. return
  970. end
  971. end
  972. end
  973. if nargs < 2
  974. loc_file = DEFAULT_ELOC;
  975. if ~exist(loc_file)
  976. fprintf('default locations file "%s" not found - specify chan_locs in topoplot() call.\n',loc_file)
  977. error(' ')
  978. end
  979. end
  980. if isempty(loc_file)
  981. loc_file = 0;
  982. end
  983. if isnumeric(loc_file) & loc_file == 0
  984. loc_file = DEFAULT_ELOC;
  985. end
  986. if nargs > 2
  987. if ~(round(nargs/2) == nargs/2)
  988. error('Odd number of input arguments??')
  989. end
  990. for i = 1:2:length(varargin)
  991. Param = varargin{i};
  992. Value = varargin{i+1};
  993. if ~isstr(Param)
  994. error('Flag arguments must be strings')
  995. end
  996. Param = lower(Param);
  997. switch Param
  998. case 'conv'
  999. CONVHULL = lower(Value);
  1000. if ~strcmp(CONVHULL,'on') & ~strcmp(CONVHULL,'off')
  1001. error('Value of ''conv'' must be ''on'' or ''off''.');
  1002. end
  1003. case 'colormap'
  1004. if size(Value,2)~=3
  1005. error('Colormap must be a n x 3 matrix')
  1006. end
  1007. colormap(Value)
  1008. case 'intsquare'
  1009. INTSQUARE = lower(Value);
  1010. if ~strcmp(INTSQUARE,'on') & ~strcmp(INTSQUARE,'off')
  1011. error('Value of ''intsquare'' must be ''on'' or ''off''.');
  1012. end
  1013. case {'interplimits','headlimits'}
  1014. if ~isstr(Value)
  1015. error('''interplimits'' value must be a string')
  1016. end
  1017. Value = lower(Value);
  1018. if ~strcmp(Value,'electrodes') & ~strcmp(Value,'head')
  1019. error('Incorrect value for interplimits')
  1020. end
  1021. INTERPLIMITS = Value;
  1022. case 'verbose'
  1023. VERBOSE = Value;
  1024. case 'nosedir'
  1025. NOSEDIR = Value;
  1026. if isempty(strmatch(lower(NOSEDIR), { '+x', '-x', '+y', '-y' }))
  1027. error('Invalid nose direction');
  1028. end;
  1029. case 'chaninfo'
  1030. CHANINFO = Value;
  1031. if isfield(CHANINFO, 'nosedir'), NOSEDIR = CHANINFO.nosedir; end;
  1032. if isfield(CHANINFO, 'shrink' ), shrinkfactor = CHANINFO.shrink; end;
  1033. if isfield(CHANINFO, 'plotrad') & isempty(plotrad), plotrad = CHANINFO.plotrad; end;
  1034. if isfield(CHANINFO, 'chantype')
  1035. chantype = CHANINFO.chantype;
  1036. if ischar(chantype), chantype = cellstr(chantype); end
  1037. CHOOSECHANTYPE = 1;
  1038. end
  1039. case 'chantype'
  1040. chantype = Value;
  1041. CHOOSECHANTYPE = 1;
  1042. if ischar(chantype), chantype = cellstr(chantype); end
  1043. if ~iscell(chantype), error('chantype must be cell array. e.g. {''EEG'', ''EOG''}'); end
  1044. case 'drawaxis'
  1045. DRAWAXIS = Value;
  1046. case 'maplimits'
  1047. MAPLIMITS = Value;
  1048. case 'masksurf'
  1049. MASKSURF = Value;
  1050. case 'circgrid'
  1051. CIRCGRID = Value;
  1052. if isstr(CIRCGRID) | CIRCGRID<100
  1053. error('''circgrid'' value must be an int > 100');
  1054. end
  1055. case 'style'
  1056. STYLE = lower(Value);
  1057. case 'numcontour'
  1058. CONTOURNUM = Value;
  1059. case 'electrodes'
  1060. ELECTRODES = lower(Value);
  1061. if strcmpi(ELECTRODES,'pointlabels') | strcmpi(ELECTRODES,'ptslabels') ...
  1062. | strcmpi(ELECTRODES,'labelspts') | strcmpi(ELECTRODES,'ptlabels') ...
  1063. | strcmpi(ELECTRODES,'labelpts')
  1064. ELECTRODES = 'labelpoint'; % backwards compatability
  1065. elseif strcmpi(ELECTRODES,'pointnumbers') | strcmpi(ELECTRODES,'ptsnumbers') ...
  1066. | strcmpi(ELECTRODES,'numberspts') | strcmpi(ELECTRODES,'ptnumbers') ...
  1067. | strcmpi(ELECTRODES,'numberpts') | strcmpi(ELECTRODES,'ptsnums') ...
  1068. | strcmpi(ELECTRODES,'numspts')
  1069. ELECTRODES = 'numpoint'; % backwards compatability
  1070. elseif strcmpi(ELECTRODES,'nums')
  1071. ELECTRODES = 'numbers'; % backwards compatability
  1072. elseif strcmpi(ELECTRODES,'pts')
  1073. ELECTRODES = 'on'; % backwards compatability
  1074. elseif ~strcmp(ELECTRODES,'off') ...
  1075. & ~strcmpi(ELECTRODES,'on') ...
  1076. & ~strcmp(ELECTRODES,'labels') ...
  1077. & ~strcmpi(ELECTRODES,'numbers') ...
  1078. & ~strcmpi(ELECTRODES,'labelpoint') ...
  1079. & ~strcmpi(ELECTRODES,'numpoint')
  1080. error('Unknown value for keyword ''electrodes''');
  1081. end
  1082. case 'dipole'
  1083. DIPOLE = Value;
  1084. case 'dipsphere'
  1085. DIPSPHERE = Value;
  1086. case 'dipnorm'
  1087. DIPNORM = Value;
  1088. case 'diplen'
  1089. DIPLEN = Value;
  1090. case 'dipscale'
  1091. DIPSCALE = Value;
  1092. case 'diporient'
  1093. DIPORIENT = Value;
  1094. case 'dipcolor'
  1095. DIPCOLOR = Value;
  1096. case 'emarker'
  1097. if ischar(Value)
  1098. EMARKER = Value;
  1099. elseif ~iscell(Value) | length(Value) > 4
  1100. error('''emarker'' argument must be a cell array {marker color size linewidth}')
  1101. else
  1102. EMARKER = Value{1};
  1103. end
  1104. if length(Value) > 1
  1105. ECOLOR = Value{2};
  1106. end
  1107. if length(Value) > 2
  1108. EMARKERSIZE2 = Value{3};
  1109. end
  1110. if length(Value) > 3
  1111. EMARKERLINEWIDTH = Value{4};
  1112. end
  1113. case 'emarker2'
  1114. if ~iscell(Value) | length(Value) > 5
  1115. error('''emarker2'' argument must be a cell array {chans marker color size linewidth}')
  1116. end
  1117. EMARKER2CHANS = abs(Value{1}); % ignore channels < 0
  1118. if length(Value) > 1
  1119. EMARKER2 = Value{2};
  1120. end
  1121. if length(Value) > 2
  1122. EMARKER2COLOR = Value{3};
  1123. end
  1124. if length(Value) > 3
  1125. EMARKERSIZE2 = Value{4};
  1126. end
  1127. if length(Value) > 4
  1128. EMARKER2LINEWIDTH = Value{5};
  1129. end
  1130. case 'shrink'
  1131. shrinkfactor = Value;
  1132. case 'intrad'
  1133. intrad = Value;
  1134. if isstr(intrad) | (intrad < MINPLOTRAD | intrad > 1)
  1135. error('intrad argument should be a number between 0.15 and 1.0');
  1136. end
  1137. case 'plotrad'
  1138. plotrad = Value;
  1139. if isstr(plotrad) | (plotrad < MINPLOTRAD | plotrad > 1)
  1140. error('plotrad argument should be a number between 0.15 and 1.0');
  1141. end
  1142. case 'headrad'
  1143. headrad = Value;
  1144. if isstr(headrad) & ( strcmpi(headrad,'off') | strcmpi(headrad,'none') )
  1145. headrad = 0; % undocumented 'no head' alternatives
  1146. end
  1147. if isempty(headrad) % [] -> none also
  1148. headrad = 0;
  1149. end
  1150. if ~isstr(headrad)
  1151. if ~(headrad==0) & (headrad < MINPLOTRAD | headrad>1)
  1152. error('bad value for headrad');
  1153. end
  1154. elseif ~strcmpi(headrad,'rim')
  1155. error('bad value for headrad');
  1156. end
  1157. case {'headcolor','hcolor'}
  1158. HEADCOLOR = Value;
  1159. case {'contourcolor','ccolor'}
  1160. CCOLOR = Value;
  1161. case {'electcolor','ecolor'}
  1162. ECOLOR = Value;
  1163. case {'emarkersize','emsize'}
  1164. EMARKERSIZE = Value;
  1165. case {'emarkersize1chan','emarkersizemark'}
  1166. EMARKERSIZE1CHAN= Value;
  1167. case {'efontsize','efsize'}
  1168. EFSIZE = Value;
  1169. case 'shading'
  1170. SHADING = lower(Value);
  1171. if ~any(strcmp(SHADING,{'flat','interp'}))
  1172. error('Invalid shading parameter')
  1173. end
  1174. case 'noplot'
  1175. noplot = Value;
  1176. if ~isstr(noplot)
  1177. if length(noplot) ~= 2
  1178. error('''noplot'' location should be [radius, angle]')
  1179. else
  1180. chanrad = noplot(1);
  1181. chantheta = noplot(2);
  1182. noplot = 'on';
  1183. end
  1184. end
  1185. case 'gridscale'
  1186. GRID_SCALE = Value;
  1187. if isstr(GRID_SCALE) | GRID_SCALE ~= round(GRID_SCALE) | GRID_SCALE < 32
  1188. error('''gridscale'' value must be integer > 32.');
  1189. end
  1190. case {'plotgrid','gridplot'}
  1191. plotgrid = 'on';
  1192. gridchans = Value;
  1193. case 'plotchans'
  1194. plotchans = Value(:);
  1195. if find(plotchans<=0)
  1196. error('''plotchans'' values must be > 0');
  1197. end
  1198. % if max(abs(plotchans))>max(Values) | max(abs(plotchans))>length(Values) -sm ???
  1199. case {'whitebk','whiteback','forprint'}
  1200. whitebk = Value;
  1201. otherwise
  1202. error(['Unknown input parameter ''' Param ''' ???'])
  1203. end
  1204. end
  1205. end
  1206. if strcmpi(whitebk, 'on')
  1207. BACKCOLOR = [ 1 1 1 ];
  1208. end;
  1209. cmap = colormap;
  1210. cmaplen = size(cmap,1);
  1211. %
  1212. %%%%%%%%%%%%%%%%%%%%%%%%%%% test args for plotting an electrode grid %%%%%%%%%%%%%%%%%%%%%%
  1213. %
  1214. if strcmp(plotgrid,'on')
  1215. STYLE = 'grid';
  1216. gchans = sort(find(abs(gridchans(:))>0));
  1217. % if setdiff(gchans,unique(gchans))
  1218. % fprintf('topoplot() warning: ''plotgrid'' channel matrix has duplicate channels\n');
  1219. % end
  1220. if ~isempty(plotchans)
  1221. if intersect(gchans,abs(plotchans))
  1222. fprintf('topoplot() warning: ''plotgrid'' and ''plotchans'' have channels in common\n');
  1223. end
  1224. end
  1225. end
  1226. %
  1227. %%%%%%%%%%%%%%%%%%%%%%%%%%% misc arg tests %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1228. %
  1229. if isempty(ELECTRODES) % if electrode labeling not specified
  1230. if length(Values) > MAXDEFAULTSHOWLOCS % if more channels than default max
  1231. ELECTRODES = 'off'; % don't show electrodes
  1232. else % else if fewer chans,
  1233. ELECTRODES = 'on'; % do
  1234. end
  1235. end
  1236. if isempty(Values)
  1237. STYLE = 'blank';
  1238. end
  1239. [r,c] = size(Values);
  1240. if r>1 & c>1,
  1241. error('input data must be a single vector');
  1242. end
  1243. Values = Values(:); % make Values a column vector
  1244. if ~isempty(intrad) & ~isempty(plotrad) & intrad < plotrad
  1245. error('intrad must be >= plotrad');
  1246. end
  1247. if ~strcmpi(STYLE,'grid') % if not plot grid only
  1248. %
  1249. %%%%%%%%%%%%%%%%%%%% Read the channel location information %%%%%%%%%%%%%%%%%%%%%%%%
  1250. %
  1251. if isstr(loc_file)
  1252. [tmpeloc labels Th Rd indices] = readlocs( loc_file,'filetype','loc');
  1253. elseif isstruct(loc_file) % a locs struct
  1254. [tmpeloc labels Th Rd indices] = readlocs( loc_file );
  1255. % Note: Th and Rd correspond to indices channels-with-coordinates only
  1256. else
  1257. error('loc_file must be a EEG.locs struct or locs filename');
  1258. end
  1259. Th = pi/180*Th; % convert degrees to radians
  1260. allchansind = 1:length(Th);
  1261. %
  1262. %%%%%%%%%% if channels-to-mark-only are given in Values vector %%%%%%%%%%%%%%%%%
  1263. %
  1264. if length(Values) < length(tmpeloc) & strcmpi( STYLE, 'blank') % if Values contains int channel indices to mark
  1265. if isempty(plotchans)
  1266. if Values ~= abs(round(Values)) | min(abs(Values))< 1 % if not positive integer values
  1267. error('Negative channel indices');
  1268. elseif strcmpi(VERBOSE, 'on')
  1269. fprintf('topoplot(): max chan number (%d) in locs > channels in data (%d).\n',...
  1270. max(indices),length(Values));
  1271. fprintf(' Marking the locations of the %d indicated channels.\n', ...
  1272. length(Values));
  1273. end
  1274. plotchans = Values;
  1275. STYLE = 'blank'; % plot channels only, marking the indicated channel number
  1276. if strcmpi(ELECTRODES,'off')
  1277. ELECTRODES = 'on';
  1278. end
  1279. else
  1280. error('input ''plotchans'' not allowed when input data are channel numbers');
  1281. end
  1282. end
  1283. if ~isempty(plotchans)
  1284. if max(plotchans) > length(Th)
  1285. error('''plotchans'' values must be <= max channel index');
  1286. end
  1287. end
  1288. %
  1289. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% channels to plot %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1290. %
  1291. if ~isempty(plotchans)
  1292. plotchans = intersect(plotchans, indices);
  1293. end;
  1294. if ~isempty(Values) & ~strcmpi( STYLE, 'blank') & isempty(plotchans)
  1295. plotchans = indices;
  1296. end
  1297. if isempty(plotchans) & strcmpi( STYLE, 'blank')
  1298. plotchans = indices;
  1299. end
  1300. %
  1301. %%%%%%%%%%%%%%%%%%%%%%%%%%% filter for channel type(s), if specified %%%%%%%%%%%%%%%%%%%%%
  1302. %
  1303. if CHOOSECHANTYPE,
  1304. newplotchans = eeg_chantype(loc_file,chantype);
  1305. plotchans = intersect(newplotchans, plotchans);
  1306. end
  1307. %
  1308. %%%%%%%%%%%%%%%%%%%%%%%%%%% filter channels used for components %%%%%%%%%%%%%%%%%%%%%
  1309. %
  1310. if isfield(CHANINFO, 'icachansind') & ~isempty(Values) & length(Values) ~= length(tmpeloc)
  1311. % test if ICA component
  1312. % ---------------------
  1313. if length(CHANINFO.icachansind) == length(Values)
  1314. % if only a subset of channels are to be plotted
  1315. % and ICA components also use a subject of channel
  1316. % we must find the new indices for these channels
  1317. plotchans = intersect(CHANINFO.icachansind, plotchans);
  1318. tmpvals = zeros(1, length(tmpeloc));
  1319. tmpvals(CHANINFO.icachansind) = Values;
  1320. Values = tmpvals;
  1321. end;
  1322. end;
  1323. %
  1324. %%%%%%%%%%%%%%%%%%% last channel is reference? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1325. %
  1326. if length(tmpeloc) == length(Values) + 1 % remove last channel if necessary
  1327. % (common reference channel)
  1328. if plotchans(end) == length(tmpeloc)
  1329. plotchans(end) = [];
  1330. end;
  1331. end;
  1332. %
  1333. %%%%%%%%%%%%%%%%%%% remove infinite and NaN values %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1334. %
  1335. if length(Values) > 1
  1336. inds = union(find(isnan(Values)), find(isinf(Values))); % NaN and Inf values
  1337. plotchans = setdiff(plotchans, inds);
  1338. end;
  1339. if strcmp(plotgrid,'on')
  1340. plotchans = setxor(plotchans,gchans);

Large files files are truncated, but you can click here to view the full file