Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_show_add.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function h=som_show_add(mode,D,varargin) | |
2 | |
3 %SOM_SHOW_ADD Shows hits, labels and trajectories on SOM_SHOW visualization | |
4 % | |
5 % h = som_show_add(mode, D, ['argID',value,...]) | |
6 % | |
7 % som_show_add('label',sMap) | |
8 % som_show_add('hit',som_hits(sMap,sD)) | |
9 % som_show_add('traj',som_bmus(sMap,sD)) | |
10 % som_show_add('comet',som_bmus(sMap,sD)) | |
11 % som_show_add('comet',inds, 'markersize', [1 0.2]) | |
12 % | |
13 % Input and output arguments ([]'s are optional): | |
14 % mode (string) operation mode 'label', 'hit', 'traj', 'comet' | |
15 % D (varies) depending on operation mode | |
16 % In 'label' mode gives the labels | |
17 % (struct) map struct, the .labels field of which is used | |
18 % (cell array of strings) size munits x number_of_labels | |
19 % In 'hit' mode gives the hit histogram(s) | |
20 % (matrix) size munits x k, if k>1, D gives hit histograms | |
21 % for k different sets of data (e.g. k classes). | |
22 % In 'traj' and 'comet' modes gives the trace of the trajectory | |
23 % (vector) size N x 1, D(1) is the current and D(end) | |
24 % is oldest item of the trajectory | |
25 % [argID, (string) Additional arguments are given as argID, value | |
26 % value] (varies) pairs. Depend on the operation mode (see below). | |
27 % | |
28 % h (vector) handles to the created objects | |
29 % | |
30 % Here are the valid argument IDs and corresponding values. Most of | |
31 % them depend on the operation mode: | |
32 % | |
33 % all modes | |
34 % 'SubPlot' (vector) which subplots are affected (default: current) | |
35 % (string) 'all': all subplots are affected | |
36 % mode = 'label' | |
37 % 'TextSize' (scalar) text size in points | |
38 % 'TextColor' (string) ColorSpec, 'xor' or 'none': label color | |
39 % | |
40 % mode = 'hit' | |
41 % 'EdgeColor' (string) ColorSpec, 'none' | |
42 % 'MarkerSize' (scalar) maximum marker size | |
43 % if k == 1, | |
44 % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'none' | |
45 % 'MarkerColor'(string) Colorspec, 'none': fill color for markers | |
46 % 'Text' (string) 'on', 'off': whether to write the number of hits | |
47 % 'TextColor' (string) ColorSpec, 'xor': text color if Text is 'on' | |
48 % 'TextSize' (scalar) text font size in points if Text is 'on' | |
49 % if k > 1, | |
50 % 'SizeFactor' (string) 'common', 'separate': size scaling | |
51 % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'pie', 'none' | |
52 % (cell array) size k x 1, marker style for each histogram | |
53 % 'MarkerColor'(string) Colorspec, 'none': fill color for markers | |
54 % (matrix) size k x 3, color for each histogram | |
55 % | |
56 % mode = 'traj' | |
57 % 'TrajWidth' (scalar) basic trajectory line width in points | |
58 % 'WidthFactor'(string) 'hit' or 'equal': effect of hits on line width | |
59 % 'TrajColor' (string) ColorSpec, 'xor': color for trajectory line | |
60 % 'Marker' (string) 'lattice', Matlab's built-in markerstyles, 'none' | |
61 % 'MarkerSize' (scalar) basic marker size (in points) | |
62 % 'SizeFactor' (string) 'equal', 'hit' (equal size/size depends on freq.) | |
63 % 'MarkerColor'(string) Colorspec, 'none': color of markers | |
64 % 'EdgeColor' (string) ColorSpec, 'none': edgecolor of markers | |
65 % | |
66 % mode = 'comet' | |
67 % 'Marker' (string) 'lattice', Matlab's built-in markerstyles | |
68 % 'MarkerColor'(string) ColorSpec, 'none': color for the markers | |
69 % (matrix) size N x 3, RGB color for each step | |
70 % 'EdgeColor' (string) ColorSpec, 'none': edgecolor for markers | |
71 % 'MarkerSize' (vector) size 1 x 2, size of comet core and tail | |
72 % | |
73 % For more help, try 'type som_show_add' or check out online documentation. | |
74 % See also SOM_SHOW. | |
75 | |
76 %%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
77 % | |
78 % som_show_add | |
79 % | |
80 % PURPOSE | |
81 % | |
82 % Shows hits, labels and trajectories on SOM_SHOW visualization | |
83 % | |
84 % SYNTAX | |
85 % | |
86 % h = som_show_add(mode, D); | |
87 % h = som_show_add(..., 'argID', value); | |
88 % | |
89 % DESCRIPTION | |
90 % | |
91 % The SOM_SHOW function makes the basic visualization of the SOM. | |
92 % With SOM_SHOW_ADD one can set labels, hit histogarms or different | |
93 % trajectories on this visualization. | |
94 % | |
95 % labels (mode = 'label') | |
96 % | |
97 % Labels are strings describing the units. They may be, e.g., a result | |
98 % of SOM_AUTOLABEL function. Labels are centered on the unit so that | |
99 % multiple labels are in a column. | |
100 % | |
101 % hit histograms (mode = 'hit') | |
102 % | |
103 % Hit histograms indicate how the best matching units of a data | |
104 % set/some data sets are distribited on a SOM. The hit histogram can | |
105 % be calculated using function SOM_HITS. | |
106 % | |
107 % trajectories (mode = 'traj' or mode = 'comet') | |
108 % | |
109 % Trajectories show the best matching units for a data set that is | |
110 % time (or any ordered) series. It may be either a line connecting the | |
111 % consecutive best matching units ('traj' mode) or a "comet" | |
112 % trajectory where the current (first sample in D) best matching unit | |
113 % has biggest marker and the oldest (last sample) has smallest | |
114 % marker ('comet' mode). | |
115 % | |
116 % NOTE: that the SOM_SHOW_ADD function can only be applied to | |
117 % figures that have been drawn by SOM_SHOW. | |
118 % | |
119 % KNOWN BUGS | |
120 % | |
121 % for 'hit' mode, if the given hit matrix is all zeros, a series of | |
122 % error messages is generated | |
123 % | |
124 % REQUIRED INPUT ARGUMENTS | |
125 % | |
126 % mode (string) Visuzalization mode | |
127 % 'label' map labeling | |
128 % 'hit' hit histograms | |
129 % 'traj' line style trajectory | |
130 % 'comet' comet style trajectory | |
131 % | |
132 % D (vector, map struct, cell array of strings) Data | |
133 % | |
134 % The valid value of D depends on the visualization mode: | |
135 % | |
136 % Mode Valid D | |
137 % 'label' map struct or Mxl cell array of strings, where | |
138 % M is number of map units and l maximum numer of | |
139 % labels in unit. | |
140 % | |
141 % 'hit' Mx1 vector or MxK matrix, where M is number of map | |
142 % units and K is number of hit histograms (of K | |
143 % different classes of data) to be shown | |
144 % | |
145 % 'comet' Lx1 vector of best matchig unit indices that have to | |
146 % 'traj' be in range of the map that is in the figure. L is | |
147 % the length of trajectory | |
148 % | |
149 % OPTIONAL INPUT ARGUMENTS | |
150 % | |
151 % Optional arguments must be given as 'argument identifier', value | |
152 % -pairs. This section is divided in four parts because each mode | |
153 % functions in a different way, though they may have same identifier | |
154 % names. | |
155 % | |
156 % If user specifies an identifier that is not operational in the | |
157 % specified mode, the functions gives a warning message. If the | |
158 % identifier does not exist in any mode the execution is terminated | |
159 % and an error message is returned. | |
160 % | |
161 % GENERAL OPTIONAL INPUT ARGUMENTS (in all modes) | |
162 % | |
163 % 'SubPlot' Target subplots in the figure | |
164 % (vector) Subplots' ordinal numbers in a vector. By default | |
165 % the target is the current subplot (see GCA). | |
166 % (string) String 'all' means all subplots. | |
167 % | |
168 % 'Marker' Data marker (not in use in 'label' mode) | |
169 % (string) 'none': sets the markers off | |
170 % 'lattice': sets the marker shape according to the | |
171 % lattice of the underlying map, i.e. it gives | |
172 % rectangles if underlying map lattice is 'rect' and | |
173 % hexagons for 'hexa', respectively | |
174 % any of the Matlab's built-in marker styles: 'o', 's', | |
175 % 'd', 'v', '^', '<' ,'> ', 'p', 'h', 'x', '.', '*', '+' | |
176 % | |
177 % NOTE that '.','x','+' or '*' are not recommended since | |
178 % they have only edgecolor and many visualizations are | |
179 % based on _face_ color. | |
180 % | |
181 % NOTE there is an important difference between built-in | |
182 % markers. If figure size is changed the 'lattice' | |
183 % markers are rescaled but the built-in markers stay at | |
184 % fixed size, and consequently, the size unit for | |
185 % 'lattice' markers is normalized but for built-in | |
186 % markers the size is given in points. For 'lattice' | |
187 % markers size 1 means the size of the map unit. | |
188 % | |
189 % NOTE that in 'hit' mode there are some additional features. | |
190 % | |
191 % 'EdgeColor' Sets edgecolor for the markers (not in use in 'label' mode) | |
192 % (string) ColorSpec, e.g. 'r', gives each edge the specified color | |
193 % 'none': sets markers edges invisible | |
194 % Default is 'none' - except if MarkerColor is set to 'none' the | |
195 % defaults is 'black'. | |
196 % | |
197 % OPTIONAL INPUT ARGUMENTS mode 'label' | |
198 % | |
199 % Labels are centered on the unit so that multiple labels are in | |
200 % a single column. | |
201 % | |
202 % 'SubPlot' see General Optional Input Arguments | |
203 % | |
204 % 'TextSize' Text size for labels | |
205 % (scalar) Text size in points. Default is 10. | |
206 % | |
207 % 'TextColor' Text color | |
208 % (string) ColorSpec specifies the text color for all labels | |
209 % 'xor': gives Matlab's "xor" text color mode where the | |
210 % label color depends on background color | |
211 % 'none': sets labels invisble (but creates the objects) | |
212 % | |
213 % OPTIONAL INPUT ARGUMENTS mode 'hit' | |
214 % | |
215 % The function in mode 'hit' depends on the input argument size. If | |
216 % only one hit histogram is drawn (K==1), it is possible to show the | |
217 % hits using numbers. This is not possible for multiple hit | |
218 % histograms (K>1). | |
219 % | |
220 % 'SubPlot' see General Optional Input Arguments | |
221 % | |
222 % 'Marker' Marker style(s) | |
223 % (string) As in General Optional Input Arguments. In addition | |
224 % 'pie': sets pie charts for markers. The size of the | |
225 % pie in each unit describes the number of total hits in the | |
226 % unit and the share of each sector is the relative amount of | |
227 % hits in each class (requires multiple histograms). Color for | |
228 % each class is set by MarkerColor. Default coloring | |
229 % is hsv(K), where K is the number of hit histograms (classes). | |
230 % (cell array) size K x 1, of built-in marker style characters. K is | |
231 % number of histograms (classes), i.e., same as size(D,2) | |
232 % where D is the second input argument. Cell value is | |
233 % valid only if multiple histograms are specified (K>1). | |
234 % | |
235 % NOTE if multiple histograms (classes) are specified | |
236 % and Marker is one of the built-in marker styles or | |
237 % 'lattice', the markers are drawn in size order from | |
238 % largest to smallest. This insures that all markers are | |
239 % visible (or at least their edges are). But if two | |
240 % markers for different classes in the same node were of | |
241 % same size, the other would be totally hidden. In order | |
242 % to prevent this, the markers for different classes are | |
243 % shifted different amounts from the exact centre of the | |
244 % unit. (Evidently, if Marker is 'pie' this problem does | |
245 % not exist.) | |
246 % | |
247 % Default marker is 'lattice' for one histogram and | |
248 % 'pie' for multiple histograms. | |
249 % | |
250 % 'MarkerColor' Marker color(s) | |
251 % (string) ColorSpec gives all markers the same color | |
252 % 'none': leaves the markes transparent (only edges are visible) | |
253 % (matrix) size K x 3, RGB triples for each histogram class | |
254 % giving each hit histogram an own color | |
255 % | |
256 % NOTE that markers '*','+','x', or '.' cannot use | |
257 % MarkerColor since these objects have no face (fill) | |
258 % color. For them only EdgeColor matters. | |
259 % | |
260 % 'MarkerSize' Maximum size for marker | |
261 % (scalar) set the _maximum_ marker size that corresponds to | |
262 % maximum hit count. If Marker is 'pie' or 'lattice' the | |
263 % MarkerSize is in normalized scale: 1 correspons to unit size. | |
264 % If Marker is one of the built-in styles, MarkerSize is given | |
265 % in points. | |
266 % | |
267 % Marker Default MarkerSize | |
268 % 'lattice' 1 (normalized units) | |
269 % 'pie' 1 (normalized units) | |
270 % 'o','s', etc. 6 (points) | |
271 % | |
272 % 'SizeFactor' Defines the scaling of the marker sizes in multiple | |
273 % histogram case (when Marker is one of the built-in marker | |
274 % styles or 'lattice'). | |
275 % (string) 'separate' (the default) means that marker size shows | |
276 % the share of the data which hits the unit compared to | |
277 % amount of data in that class. That is, the size of | |
278 % markers show the relative distribution of data on the map | |
279 % in each class separately. The maximum size is SizeFactor. | |
280 % 'common' means that marker size shows the distribution of | |
281 % the data in the different classes compared to | |
282 % _the total amount of data_. | |
283 % | |
284 % 'EdgeColor' Sets edgecolor for the markers, see General | |
285 % Optional Input Arguments. Default is 'none' - | |
286 % except if MarkerColor is 'none' or Marker is | |
287 % 'x','*,'x', or '.'. In these cases default EdgeColor is 'black'. | |
288 % | |
289 % 'Text' Write/don't write the number of hits on the | |
290 % units. This option is not in use for multiple histograms. | |
291 % (string) 'on' or 'off' (the default) | |
292 % | |
293 % 'TextColor' Text color | |
294 % (string) ColorSpec gives each letter the same color | |
295 % 'xor' gives a "xor" coloring for the text | |
296 % | |
297 % 'TextSize' Text size (in points) | |
298 % (scalar) text size in points, default is 10 | |
299 % | |
300 % OPTIONAL INPUT ARGUMENTS mode 'traj' | |
301 % | |
302 % Input D is a Nx1 vector of N BMU indices that describe the trace of the | |
303 % comet. First element D(1) is "newest" and D(end) "oldest". Note | |
304 % that at least two indeces are expected: size of D must be at | |
305 % least 2x1. | |
306 % | |
307 % 'SubPlot' see General Optional Input Arguments | |
308 % | |
309 % 'TrajColor' Color for trajectory line | |
310 % (string) ColorSpec gives each marker the same color, 'w' by default | |
311 % 'none' sets the marker fill invisible: only edges are shown | |
312 % | |
313 % 'TrajWidth' Maximum width of trajectory line | |
314 % (scalar) width in points. Default is 3. | |
315 % | |
316 % 'WidthFactor' Shows how often edge between two units has been traversed. | |
317 % (string) 'hit': the size of the marker shows how frequent the | |
318 % trajectory visits the unit (TrajWidth sets the | |
319 % maximum size). This is the default. | |
320 % 'equal': all lines have the same width (=TrajWidth) | |
321 % | |
322 % 'Marker' Marker style, see General Optional Input | |
323 % Arguments. Default is 'o'. | |
324 % | |
325 % NOTE Marker style 'lattice' is not valid in mode 'traj'. | |
326 % NOTE Markers can be turned off by setting MarkerSize to zero. | |
327 % | |
328 % 'MarkerSize' Maximum size of markers | |
329 % (scalar) Default is 12 (points). | |
330 % | |
331 % 'SizeFactor' Sets the frequency based marker size or constant marker size. | |
332 % (string) 'hit': the size of the marker shows how frequent the | |
333 % trajectory visits the unit (MarkerSize sets the | |
334 % maximum size). This is the default. | |
335 % 'equal': all markers have th esame size (=MarkerSize) | |
336 % | |
337 % 'MarkerColor' The fill color(s) for hit markers | |
338 % (string) ColorSpec gives each marker the same color, default is 'w' | |
339 % 'none' sets the marker fill invisible: only edges are shown | |
340 % | |
341 % NOTE markers '*','+','x', or '.' can't use MarkerColor since | |
342 % these objects have no face (fill) color: only EdgeColor | |
343 % matters for these markers. | |
344 % | |
345 % 'EdgeColor' see General Optional Input Arguments. Default is | |
346 % 'none' - except if MarkerColor is 'none' or Marker | |
347 % is 'x','*','x', or '.'. In these cases default | |
348 % EdgeColor is 'white'. | |
349 % | |
350 % OPTIONAL INPUT ARGUMENTS mode 'comet' | |
351 % | |
352 % Input D is a Nx1 vector of N BMU indices that describe the trace of | |
353 % the comet. First element D(1) is "newest" and D(end) "oldest". Note | |
354 % that at least two indeces are expected: size of D must be at least | |
355 % 2x1. | |
356 % | |
357 % 'SubPlot' see General Optional Input Arguments | |
358 % | |
359 % 'Marker' Marker style, see General Optional Input | |
360 % Arguments. Default is 'lattice'. | |
361 % | |
362 % 'MarkerColor' The fill color(s) for comet markers | |
363 % (string) ColorSpec gives each marker the same color, default is 'w' | |
364 % 'none' sets the marker fill invisible: only edges are shown | |
365 % (matrix) size N x 3, consisting of RGB triples as rows | |
366 % sets different color for each marker. This may be | |
367 % used to code the time series using color/grayscale. | |
368 % | |
369 % NOTE Markers '*','+','x', or '.' can't use MarkerColor | |
370 % since these objects have no face (fill) color: only | |
371 % EdgeColor matters for these markers. | |
372 % | |
373 % 'EdgeColor' see General Optional Input Arguments. Default is | |
374 % 'none' - except if MarkerColor is 'none' or Marker | |
375 % is 'x','*,'x', or '.'. In these cases default | |
376 % EdgeColor is 'white'. | |
377 % | |
378 % 'MarkerSize' The size of "comet core" and tail | |
379 % (vector) size 1 x 2: first element sets the size for the marker | |
380 % representing D(1) and the second set size for D(end) | |
381 % the size (area) of the markes between these changes linearly. | |
382 % Note that size units for 'lattice' marker style are | |
383 % normalized so that 1 means map unit size but for built-in | |
384 % marker styles the size is given points. | |
385 % | |
386 % Marker default value | |
387 % 'lattice' [0.8 0.1] | |
388 % 'o','v', etc. [20 4] | |
389 % | |
390 % OUTPUT ARGUMENTS | |
391 % | |
392 % h (vector) handles to all objects created by the function | |
393 % | |
394 % OBJECT TAGS | |
395 % | |
396 % Field Tag in every object is set to | |
397 % | |
398 % 'Lab' for objects created in mode 'label' | |
399 % 'Hit' -"- 'hit' | |
400 % 'Traj' -"- 'traj' | |
401 % 'Comet' -"- 'comet' | |
402 % | |
403 % EXAMPLES | |
404 % | |
405 % Not yet ready | |
406 % | |
407 % SEE ALSO | |
408 % | |
409 % som_show Basic map visualization | |
410 % som_show_clear Clear hit marks, labels or trajectories from current figure. | |
411 | |
412 % Copyright (c) 1999-2000 by the SOM toolbox programming team. | |
413 % http://www.cis.hut.fi/projects/somtoolbox/ | |
414 | |
415 % Version 2.0beta Johan 131199 | |
416 | |
417 %% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
418 | |
419 error(nargchk(2,Inf,nargin)) % check no. of input args | |
420 | |
421 % Get data from the SOM_SHOW figure, exit if error | |
422 | |
423 [handles,msg,lattice,msize,dim]=vis_som_show_data('all',gcf); | |
424 error(msg); | |
425 | |
426 munits=prod(msize); | |
427 % Initialize some variables: these must exist later; | |
428 % the default values are set by subfunctions | |
429 | |
430 Property=init_properties; | |
431 Property.handles=handles; | |
432 | |
433 %%% Check mode and that D is of right type & size for that mode | |
434 % mode has to be string | |
435 if ~vis_valuetype(mode,{'string'}), | |
436 error('String value expected for first input argument (mode).'); | |
437 else | |
438 mode=lower(mode); % case insensitive | |
439 mode_=mode; % 'mode' is internal variable; | |
440 % for program constructs 'mode_' is shown to | |
441 % user in some error messags | |
442 end | |
443 | |
444 switch mode % check mode | |
445 case 'hit' | |
446 %%% Hit histogram visualization: vector [msize k] | |
447 | |
448 if ~vis_valuetype(D,{'nxm'}), | |
449 error('Hit visualization: a matrix expected for data input.'); | |
450 elseif size(D,1) ~= prod(msize) | |
451 error('Hit visualization: data and map size do not match.'); | |
452 end | |
453 % Multiple hit histograms | |
454 if size(D,2)>1 | |
455 mode='mhit'; | |
456 % Hit count musn't be negative | |
457 if any(D(:)<0), | |
458 error('Hit visualization: negative hit count in data not allowed!'); | |
459 end | |
460 end | |
461 | |
462 case {'traj','comet'} | |
463 %%% Trajectory like visualizations | |
464 | |
465 if ~vis_valuetype(D,{'nx1'}), | |
466 error('Trajectory/Comet: a Nx1 vector expected for data input.'); | |
467 elseif any(D>prod(msize))| any(D<1), | |
468 error('Trajectory/Comet: BMU indices out of range in data input.'); | |
469 elseif any(fix(D)~=D), | |
470 warning('Trajectory/Comet: BMU indices not integer. Rounding...'); | |
471 elseif size(D,1)<2 | |
472 error('At least two BMU indexes expected.'); | |
473 end | |
474 | |
475 case 'label' | |
476 %%% Label visualizations | |
477 | |
478 if isstruct(D), % check if D is a map | |
479 [tmp,ok,tmp]=som_set(D); | |
480 if all(ok) & strcmp(D.type,'som_map') | |
481 ; | |
482 else | |
483 error('Map struct is invalid!'); | |
484 end | |
485 % Size check | |
486 if length(msize) ~= length(D.topol.msize) | ... | |
487 munits ~= prod(D.topol.msize), | |
488 error(['The size of the input map and the map in the figure' ... | |
489 ' do not match.']); | |
490 end | |
491 D=D.labels; | |
492 % Cell input | |
493 elseif vis_valuetype(D,{'2Dcellarray_of_char'}) | |
494 ; | |
495 % Char input | |
496 elseif vis_valuetype(D,{'char_array'}), | |
497 D=cellstr(D); | |
498 else | |
499 error(['Labels has to be in a map struct or in a cell array' ... | |
500 ' of strings']); | |
501 end | |
502 if size(D,1) ~= munits | |
503 error(['The number of labels does not match the size of the map' ... | |
504 ' in the figure.']); | |
505 end | |
506 otherwise | |
507 error('Invalid visualization mode.'); | |
508 end | |
509 | |
510 if rem(length(varargin),2) | |
511 error('Mismatch in identifier-value pairs or wrong input argument order.'); | |
512 end | |
513 | |
514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
515 % read in optional arguments | |
516 | |
517 for i=1:2:length(varargin), | |
518 %% Check that all argument types are strings | |
519 | |
520 if ~ischar(varargin{i}) | |
521 error('Invalid identifier name or input argument order.'); | |
522 end | |
523 | |
524 %% Lower/uppercase in identifier types doesn't matter: | |
525 | |
526 identifier=lower(varargin{i}); % identifier (lowercase) | |
527 value=varargin{i+1}; | |
528 | |
529 % Check property identifiers and values and store the values. | |
530 % Struct used_in is set to initiate warning messages: | |
531 % if a don't care propersty is set, the user is warned. | |
532 | |
533 switch identifier | |
534 case 'marker' | |
535 %%% Marker for hits or trajectories | |
536 switch mode | |
537 case 'mhit' | |
538 if vis_valuetype(value,{'markerstyle'}) | ... | |
539 (vis_valuetype(value,{'string'}) & ... | |
540 any(strcmp(value,{'lattice','pie'}))), | |
541 ; % ok | |
542 elseif vis_valuetype(value,{'cellcolumn_of_char'}), | |
543 if size(value,1) ~= size(D,2) | |
544 error([' If a cell of Markers is specified its size must be' ... | |
545 ' number_of_hit_histograms x 1.']); | |
546 else | |
547 for i=1:size(D,2), | |
548 if ~vis_valuetype(value{i},{'markerstyle'}) | |
549 error('Cell input for ''Marker'' contains invalid styles.') | |
550 end | |
551 end | |
552 end | |
553 else | |
554 error([' Invalid ''Marker'' in case of multiple hit histograms.' ... | |
555 char(10) ' See detailed documentation.']) | |
556 end | |
557 case {'comet','hit'} | |
558 if vis_valuetype(value,{'markerstyle'}) | isempty(value), | |
559 % ok; | |
560 elseif ischar(value) & strcmp(value,'lattice'), | |
561 % ok; | |
562 else | |
563 error(['Marker must be Matlab''s marker style, or string' ... | |
564 ' ''lattice''.']); | |
565 end | |
566 case 'traj' | |
567 if ~vis_valuetype(value,{'markerstyle'}) & ~isempty(value), | |
568 error('In mode ''traj'' Marker must be one of Matlab''s built-in marker styles'); | |
569 end | |
570 end | |
571 used_in.comet=1; % Set relevance flags | |
572 used_in.traj=1; | |
573 used_in.label=0; | |
574 used_in.hit=1; | |
575 used_in.mhit=1; | |
576 | |
577 case 'markersize' | |
578 %%% Marker for hits or trajectories | |
579 switch mode | |
580 case 'comet' | |
581 if ~vis_valuetype(value,{'1x2'}) & ~isempty(value), | |
582 error('In mode ''comet'' MarkerSize'' must be a 1x2 vector.'); | |
583 end | |
584 case {'hit','traj'} | |
585 if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), | |
586 error(['In mode ''' mode_ ... | |
587 ''' ''MarkerSize'' must be a scalar.']); | |
588 end | |
589 end | |
590 used_in.comet=1; % Set relevance flags | |
591 used_in.traj=1; | |
592 used_in.label=0; | |
593 used_in.hit=1; | |
594 used_in.mhit=1; | |
595 | |
596 case 'sizefactor' | |
597 %%% Hit dependent size factor | |
598 switch mode | |
599 case 'traj' | |
600 if ~vis_valuetype(value,{'string'}) | ... | |
601 ~any(strcmp(value,{'hit', 'equal'})), | |
602 error(['In mode ''traj'' ''SizeFactor'' must be ' ... | |
603 'string ''equal'' or ''hit''.']); | |
604 end | |
605 case 'mhit' | |
606 if ~vis_valuetype(value,{'string'}) | ... | |
607 ~any(strcmp(value,{'common', 'separate'})), | |
608 error(['In mode ''hit'' ''SizeFactor'' must be ' ... | |
609 'string ''common'' or ''separate''.']); | |
610 end | |
611 end | |
612 used_in.comet=0; % Set relevance flags | |
613 used_in.traj=1; | |
614 used_in.label=0; | |
615 used_in.hit=0; | |
616 used_in.mhit=1; | |
617 | |
618 case 'markercolor' | |
619 %%% Markercolor | |
620 switch mode | |
621 case 'comet' | |
622 if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... | |
623 ~vis_valuetype(value,{'nx3rgb',[size(D,1) 3]},'all') & ... | |
624 ~isempty(value), | |
625 error(['MarkerColor in mode ''comet'' must be a ColorSpec,' ... | |
626 ' string ''none'' or Mx3 matrix of RGB triples.']); | |
627 end | |
628 case 'mhit' | |
629 if ~vis_valuetype(value,{[size(D,2) 3],'nx3rgb'},'all') & ... | |
630 ~vis_valuetype(value,{'colorstyle','1x3rgb'}), | |
631 error([' If multiple hit histograms in mode ''hit'' are' ... | |
632 char(10) ... | |
633 ' given MarkerColor must be ColorSpec or a Kx3 matrix' ... | |
634 char(10)... | |
635 ' of RGB triples where K is the number of histograms.']); | |
636 end | |
637 case 'hit' | |
638 if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... | |
639 ~isempty(value), | |
640 error(['MarkerColor in mode ''hit'' ' ... | |
641 'must be a ColorSpec or string ''none''.']); | |
642 end | |
643 case 'traj' | |
644 if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ... | |
645 ~isempty(value), | |
646 error(['MarkerColor in mode ''traj'' ' ... | |
647 'must be a ColorSpec or string ''none''.']); | |
648 end | |
649 end | |
650 | |
651 used_in.comet=1; % Set relevance flags | |
652 used_in.traj=1; | |
653 used_in.label=0; | |
654 used_in.hit=1; | |
655 used_in.mhit=1; | |
656 | |
657 case 'edgecolor' | |
658 %%% Color for marker edges | |
659 if ~vis_valuetype(value,{'colorstyle','1x3rgb'}) & ~isempty(value), | |
660 error('''EdgeColor'' must be a ColorSpec or string ''none''.') | |
661 end | |
662 | |
663 used_in.comet=1; % Set relevance flags | |
664 used_in.traj=1; | |
665 used_in.label=0; | |
666 used_in.hit=1; | |
667 used_in.mhit=1; | |
668 | |
669 case 'text' | |
670 %%% Labeling for trajectories/hits | |
671 switch mode | |
672 case 'hit' | |
673 %%% Hit count using numbers? | |
674 if isempty(value), | |
675 value='off'; | |
676 elseif vis_valuetype(value,{'string'}) & ... | |
677 ~any(strcmp(value,{'on','off'})), | |
678 error('Value for Text in mode ''hit'' should be ''on'' or ''off''.'); | |
679 else | |
680 ; % ok | |
681 end | |
682 %case 'traj','comet' | |
683 % if ~vis_valuetype(value,{'char_array','cellcolumn_of_char'}) & ... | |
684 % ~isempty(value) | |
685 % error('Value for Text is of wrong type or size.') | |
686 % elseif ischar(value) | |
687 % value=strcell(value) % ok, convert to cell | |
688 % end | |
689 % if size(traj_label,1)~=size(D,1) | |
690 % error(['The number of labels in Text and the length of the' ... | |
691 % ' trajectory do not match.']); | |
692 % end | |
693 case 'label' | |
694 ; % not used | |
695 end | |
696 used_in.comet=0; % Set relevance flags | |
697 used_in.traj=0; | |
698 used_in.label=0; | |
699 used_in.hit=1; | |
700 used_in.mhit=0; | |
701 | |
702 case 'textsize' | |
703 %%% Text size for labels | |
704 | |
705 if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), | |
706 error('TextSize must be scalar.'); | |
707 end | |
708 used_in.comet=0; % Set relevance flags | |
709 used_in.traj=0; | |
710 used_in.label=1; | |
711 used_in.hit=1; | |
712 used_in.mhit=0; | |
713 | |
714 case 'textcolor' | |
715 %%% Color for labels | |
716 | |
717 if ~vis_valuetype(value,{'colorstyle','1x3rgb','xor'}) & ~isempty(value), | |
718 error('''TextColor'' must be ColorSpec, ''xor'' or ''none''.') | |
719 end | |
720 used_in.comet=0; % Set relevance flags | |
721 used_in.traj=0; | |
722 used_in.label=1; | |
723 used_in.hit=1; | |
724 used_in.mhit=0; | |
725 | |
726 case 'trajwidth' | |
727 %%% Basic line width for a line trajectory | |
728 if ~vis_valuetype(value,{'1x1'}) & ~isempty(value), | |
729 error('TrajWidth must be a scalar.'); | |
730 end | |
731 used_in.comet=0; % Set relevance flags | |
732 used_in.traj=1; | |
733 used_in.label=0; | |
734 used_in.hit=0; | |
735 used_in.mhit=0; | |
736 | |
737 case 'widthfactor' | |
738 %%% Hit factor for a line trajectory | |
739 if ~vis_valuetype(value,{'string'}) | ... | |
740 ~any(strcmp(value,{'hit', 'equal'})), | |
741 error(['In mode ''traj'' ''WidthFactor'' must be ' ... | |
742 'string ''equal'' or ''hit''.']); | |
743 end | |
744 used_in.comet=0; % Set relevance flags | |
745 used_in.traj=1; | |
746 used_in.label=0; | |
747 used_in.hit=0; | |
748 used_in.mhit=0; | |
749 | |
750 case 'trajcolor' | |
751 %%% Color for trajectory line | |
752 | |
753 if ~vis_valuetype(value,{'colorstyle','1x3rgb','xor'}) & ~isempty(value), | |
754 error('''TrajColor'' must be a ColorSpec or string ''xor''.') | |
755 end | |
756 used_in.comet=0; % Set relevance flags | |
757 used_in.traj=1; | |
758 used_in.label=0; | |
759 used_in.hit=0; | |
760 used_in.mhit=0; | |
761 | |
762 case 'uselabel' | |
763 %%% Which labels to show | |
764 error('Not yet implemented.'); | |
765 | |
766 case 'shift' | |
767 if ~vis_valuetype(value,{'1x1'}) | ((value < 0) | (value > 1)), | |
768 error('''Shift'' must be a scalar in range [0,1].') | |
769 end | |
770 used_in.comet=0; % Set relevance flags | |
771 used_in.traj=0; | |
772 used_in.label=0; | |
773 used_in.hit=0; | |
774 used_in.mhit=1; | |
775 | |
776 case 'subplot' | |
777 %%% The subplots which are affected | |
778 | |
779 if vis_valuetype(value,{'1xn','nx1','string'}), | |
780 if ischar(value), | |
781 if ~strcmp(value,'all'), | |
782 error('Only valid string value for subplot indices is ''all''.'); | |
783 else | |
784 value=1:length(handles); | |
785 end | |
786 elseif any(value<1) | any(value>length(handles)), | |
787 error('Subplot indices must be in range 1...number_of_subplots!'); | |
788 end | |
789 elseif ~isempty(value) | |
790 error('Invalid subplot indices!'); | |
791 end | |
792 used_in.comet=1; % Set relevance flags | |
793 used_in.traj=1; | |
794 used_in.label=1; | |
795 used_in.hit=1; | |
796 used_in.mhit=1; | |
797 | |
798 otherwise | |
799 error([ 'Unknown identifier ''' identifier '''.']); | |
800 end | |
801 | |
802 % Warn user if the property that was set has no effect in the | |
803 % selected visuzlization mode | |
804 | |
805 if ~getfield(used_in, mode), | |
806 warning(['Property ''' identifier ''' has no effect in mode ''' ... | |
807 mode_ '''.']); | |
808 else | |
809 Property=setfield(Property,identifier,value); | |
810 end | |
811 end | |
812 | |
813 % set default subplot | |
814 if isempty(Property.subplot) | |
815 % search the subplot number for current axis | |
816 value=find(gca==handles); | |
817 if isempty(value) | value>length(handles) | |
818 error('SubPlot default value setting: current axis is not in the figure!'); | |
819 else | |
820 Property.subplot=value; | |
821 end | |
822 end | |
823 | |
824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
825 %%%%%%% Main switch: select the right subfunction %%%%%%%%%%%%%%%%%%% | |
826 | |
827 switch mode | |
828 case 'hit' | |
829 h_=hit(D, lattice, msize, Property); | |
830 case 'mhit' | |
831 h_=mhit(D, lattice, msize, Property); | |
832 case 'label' | |
833 h_=label(D, lattice, msize, Property); | |
834 case 'traj' | |
835 h_=traj(D, lattice, msize, Property); | |
836 case 'comet' | |
837 %error('Not yet implemented.'); | |
838 h_=comet(D, lattice, msize, Property); | |
839 otherwise | |
840 error('Whoops! Internal error: unknown mode!'); | |
841 end | |
842 | |
843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
844 %% Build output if necessary %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
845 | |
846 if nargout>0 | |
847 h=h_; | |
848 end | |
849 | |
850 %%%% SUBFUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
851 | |
852 function h_=hit(Hits, lattice, msize, Property); | |
853 | |
854 % number of map units | |
855 munits=prod(msize); | |
856 | |
857 % subplots | |
858 p=Property.subplot; | |
859 handles=Property.handles; | |
860 | |
861 % Set default marker | |
862 if isempty(Property.marker), | |
863 if strcmp(Property.text,'on') | |
864 Property.marker='none'; | |
865 else | |
866 Property.marker='lattice'; | |
867 end | |
868 end | |
869 | |
870 % Set default markersize | |
871 if isempty(Property.markersize) | |
872 if strcmp(Property.marker,'none'), | |
873 warning('MarkerSize is not meaningful since Marker is set to ''none''.'); | |
874 elseif strcmp(Property.marker,'lattice'), | |
875 Property.markersize=1; % normalized size | |
876 else | |
877 Property.markersize=12; % points | |
878 end | |
879 end | |
880 | |
881 % Set default colors | |
882 if ~isempty(Property.markercolor), | |
883 if strcmp(Property.marker,'none') | |
884 warning('MarkerColor is not used since Marker is set to ''none''.'); | |
885 Property.markercolor=[]; % not used | |
886 else | |
887 ; % ok | |
888 end | |
889 elseif any(strcmp(Property.marker,{'+','*','.','x'})), | |
890 % these don't use fill color: 'none' will cause default | |
891 % edgecolor to be 'k'. | |
892 Property.markercolor='none'; | |
893 else | |
894 Property.markercolor='k'; | |
895 end | |
896 | |
897 if ~isempty(Property.edgecolor), | |
898 if strcmp(Property.marker,'none') | |
899 warning(['EdgeColor is not used since Marker is set to' ... | |
900 ' ''none''.']); | |
901 else | |
902 ; %ok | |
903 end | |
904 elseif ~strcmp(Property.markercolor,'none'), | |
905 Property.edgecolor='none'; | |
906 else | |
907 Property.edgecolor='k'; | |
908 end | |
909 | |
910 % Set default text | |
911 if isempty(Property.text), | |
912 Property.text='off'; | |
913 end | |
914 | |
915 % Set default textsize | |
916 if isempty(Property.textsize) | |
917 Property.textsize=10; | |
918 elseif strcmp(Property.text,'off') | |
919 warning('TextSize not used as hits are not set to be shown as numbers.'); | |
920 end | |
921 | |
922 % Set default textcolor | |
923 if isempty(Property.textcolor) | |
924 Property.textcolor='w'; | |
925 elseif strcmp(Property.text,'off') | |
926 warning('TextColor not used as hits are not set to be shown as numbers.'); | |
927 end | |
928 | |
929 %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
930 | |
931 h_=[]; % this variable is for collecting the object handles | |
932 | |
933 % Select the drawing mode | |
934 | |
935 if ~strcmp(Property.marker,'none') | |
936 | |
937 %%%%% Draw spots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
938 | |
939 % unit coordinates | |
940 coord=som_vis_coords(lattice,msize); | |
941 | |
942 % Calculate the size of the spots | |
943 mx=max(Hits); | |
944 | |
945 if mx==0, | |
946 % nothing to draw! | |
947 h_=[]; | |
948 return | |
949 else | |
950 Size=sqrt(Hits./mx); | |
951 end | |
952 % coordinates for non-zero hits (only those are drawn) | |
953 coord=coord(Size~=0,:); | |
954 Size=Size(Size~=0); | |
955 N=size(Size,1); | |
956 | |
957 % som_cplane can't draw one unit with arbitrary | |
958 % coordinates as it its mixed with msize: | |
959 if size(coord,1)==1 & strcmp(Property.marker,'lattice'), | |
960 Size=[Size;Size]; | |
961 coord=[coord;coord]; | |
962 end | |
963 | |
964 for i=1:length(p), | |
965 % Set axes | |
966 axes(handles(p(i))); | |
967 % Get hold state and caxis | |
968 memhold=ishold; cax=caxis; | |
969 hold on; | |
970 | |
971 switch Property.marker | |
972 case 'lattice' | |
973 h_(i,1)=som_cplane(lattice, coord, Property.markercolor, ... | |
974 Property.markersize*Size); | |
975 otherwise | |
976 [S,m]=som_grid(lattice, [N 1],... | |
977 'Coord',coord, ... | |
978 'Line','none',... | |
979 'Marker',Property.marker,... | |
980 'MarkerColor',Property.markercolor,... | |
981 'MarkerSize', Size*Property.markersize); | |
982 h_=[h_;m(:)]; | |
983 end | |
984 | |
985 % Restore hold state | |
986 if ~memhold | |
987 hold off; | |
988 end | |
989 end | |
990 | |
991 % Set edgecolor | |
992 if strcmp(Property.marker,'lattice') | |
993 set(h_,'edgecolor',Property.edgecolor); | |
994 else | |
995 set(h_,'markeredgecolor',Property.edgecolor); | |
996 end | |
997 end | |
998 | |
999 if strcmp(Property.text,'on'), | |
1000 %%%%% Draw numbers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1001 | |
1002 % Do numbers | |
1003 Hits=reshape(Hits,[munits 1]); | |
1004 labels=cell([munits 1]); | |
1005 for i=1:length(Hits) | |
1006 if Hits(i) % zero hit won't be shown | |
1007 labels(i)={num2str(Hits(i))}; | |
1008 end | |
1009 end | |
1010 | |
1011 for i=1:length(p), | |
1012 axes(handles(p(i))); % Set axes | |
1013 memhold=ishold; % Get hold state | |
1014 hold on; | |
1015 [S,m,l,t]=som_grid(lattice, msize, ... | |
1016 'Line','none',... | |
1017 'Marker','none', ... | |
1018 'Label',labels, ... | |
1019 'LabelColor', Property.textcolor, ... | |
1020 'LabelSize', Property.textsize); | |
1021 % Get handles | |
1022 h_=[h_;t(:)]; | |
1023 | |
1024 % Restore hold state and caxis | |
1025 if ~memhold | |
1026 hold off; | |
1027 end | |
1028 caxis(cax); | |
1029 end | |
1030 | |
1031 % Remove zero object handles (missing objects) | |
1032 h_=setdiff(h_,0); | |
1033 end | |
1034 | |
1035 %% Set object tags (for som_show_clear) %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1036 | |
1037 set(h_,'Tag','Hit') | |
1038 | |
1039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1040 | |
1041 function h_=mhit(Hits, lattice, msize, Property); | |
1042 | |
1043 % number of map units | |
1044 munits=prod(msize); | |
1045 | |
1046 % subplots | |
1047 p=Property.subplot; | |
1048 handles=Property.handles; | |
1049 | |
1050 | |
1051 % Set default marker | |
1052 if isempty(Property.marker), | |
1053 Property.marker=lattice; | |
1054 end | |
1055 | |
1056 % variable 'mode' indicates which kind of markers are used: | |
1057 | |
1058 if iscell(Property.marker), | |
1059 mode='marker'; | |
1060 elseif vis_valuetype(Property.marker,{'markerstyle'}), | |
1061 mode='marker'; | |
1062 elseif strcmp(Property.marker,'pie'), | |
1063 mode='pie'; | |
1064 else | |
1065 mode='lattice'; | |
1066 end | |
1067 | |
1068 % Set default size scaling | |
1069 if isempty(Property.sizefactor) | |
1070 Property.sizefactor='separate'; | |
1071 end | |
1072 | |
1073 % Set default markersize | |
1074 if isempty(Property.markersize) | |
1075 if any(strcmp(mode,{'lattice','pie'})), | |
1076 Property.markersize=1; % normalized | |
1077 else | |
1078 Property.markersize=12; % points | |
1079 end | |
1080 end | |
1081 | |
1082 % Set default colors | |
1083 | |
1084 if isempty(Property.markercolor), | |
1085 Property.markercolor=hsv(size(Hits,2)); | |
1086 end | |
1087 | |
1088 if isempty(Property.edgecolor), | |
1089 if vis_valuetype(Property.markercolor,{'none'}), | |
1090 Property.edgecolor='k'; | |
1091 else | |
1092 Property.edgecolor='none'; | |
1093 end | |
1094 end | |
1095 | |
1096 % Set default shift | |
1097 if isempty(Property.shift) | |
1098 Property.shift=0; | |
1099 end | |
1100 | |
1101 %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1102 | |
1103 h_=[]; % this variable is for collecting the object handles | |
1104 | |
1105 switch mode | |
1106 case {'marker','lattice'} | |
1107 % Number of hits histograms | |
1108 n_Hits=size(Hits,2); | |
1109 % Calculate the size of the spots | |
1110 | |
1111 if strcmp(Property.sizefactor,'common') | |
1112 mx=max(max(Hits)); | |
1113 if mx==0 % nothing to draw! | |
1114 h_=[]; return | |
1115 end | |
1116 spotSize=sqrt(Hits./mx); | |
1117 else | |
1118 mx=repmat(max(Hits),munits,1); | |
1119 mx(mx==0)=1; % Prevent division by zero | |
1120 spotSize=sqrt(Hits./mx); | |
1121 end | |
1122 | |
1123 %%% Make spotSize | |
1124 | |
1125 %reshape Size to a vector [spotSizeforHist(:,1); spotSizeforHist(:,2);...] | |
1126 spotSize=spotSize(:); | |
1127 | |
1128 % indices for non-zero hits (only those are drawn) | |
1129 notZero=find(spotSize ~= 0); | |
1130 | |
1131 % Drop zeros away from spotSize | |
1132 spotSize=spotSize(notZero); | |
1133 | |
1134 % Order spots so that bigger will be drawn first, so that they | |
1135 % won't hide smaller ones | |
1136 [dummy, sizeOrder]=sort(spotSize); sizeOrder=sizeOrder(end:-1:1); | |
1137 spotSize=spotSize(sizeOrder); | |
1138 | |
1139 %%% Make unit coordinates | |
1140 coord=som_vis_coords(lattice,msize); | |
1141 | |
1142 move=repmat(linspace(-.1,.1,n_Hits),size(coord,1),1)*Property.shift; | |
1143 move=repmat(move(:),1,2); | |
1144 | |
1145 % do n_Hits copies of unit coordinates so that they match spotSize | |
1146 coord=repmat(coord,n_Hits,1)+move; | |
1147 | |
1148 % Drop zeros away from coords and order | |
1149 coord=coord(notZero,:); | |
1150 coord=coord(sizeOrder,:); | |
1151 | |
1152 %%% Make unit colors | |
1153 | |
1154 if vis_valuetype(Property.markercolor,{'nx3'}), | |
1155 % If multiple colors Copy unit colors so that they match spotSize | |
1156 color=Property.markercolor(reshape(repmat([1:n_Hits]',1,munits)',... | |
1157 munits*n_Hits,1),:); | |
1158 % drop zeros away & order | |
1159 color=color(notZero,:); | |
1160 color=color(sizeOrder,:); | |
1161 else | |
1162 % only on color | |
1163 color=Property.markercolor; | |
1164 end | |
1165 | |
1166 %%% Make unit markers | |
1167 | |
1168 if iscell(Property.marker), | |
1169 %marker shows class: | |
1170 marker=char(Property.marker); | |
1171 marker=marker(reshape(repmat([1:n_Hits]',1,munits)',... | |
1172 munits*n_Hits,1),:); | |
1173 % Drop zeros, order & make to cell array (for som_grid) | |
1174 marker=marker(notZero,:); | |
1175 marker=cellstr(marker(sizeOrder,:)); | |
1176 else | |
1177 marker=Property.marker; | |
1178 end | |
1179 | |
1180 % som_cplane can't draw one unit with arbitrary | |
1181 % coordinates as it its mixed with msize: | |
1182 if size(coord,1)==1 & strcmp(mode,'lattice'), | |
1183 spotSize = [spotSize; spotSize]; | |
1184 coord = [coord; coord]; | |
1185 end | |
1186 | |
1187 N=length(notZero); % for som_grid visuzalization routine | |
1188 case 'pie' | |
1189 % marker 'pie' requires size parameter totHits | |
1190 if strcmp(mode,'pie') | |
1191 coord=som_vis_coords(lattice, msize); | |
1192 notZero=sum(Hits,2)>0; | |
1193 Hits=Hits(notZero,:); | |
1194 coord=coord(notZero,:); | |
1195 N=size(notZero,1); | |
1196 totHits=sqrt(sum(Hits,2)./max(sum(Hits,2))); | |
1197 end | |
1198 | |
1199 % som_pieplane can't draw one unit with arbitrary | |
1200 % coordinates as it its mixed with msize: | |
1201 if size(coord,1)==1, | |
1202 Hits= [Hits; Hits]; | |
1203 coord = [coord; coord]; | |
1204 end | |
1205 otherwise | |
1206 error('Whoops: internal error. Bad mode in subfunction mhit'); | |
1207 end | |
1208 | |
1209 for i=1:length(p), %%% Main loop begins | |
1210 % Set axis | |
1211 axes(handles(p(i))); | |
1212 % Get hold state and caxis | |
1213 memhold=ishold; cax=caxis; | |
1214 hold on; | |
1215 | |
1216 switch mode | |
1217 case 'lattice' | |
1218 h_(i,1)=som_cplane(lattice, coord, color, spotSize*Property.markersize); | |
1219 case 'marker' | |
1220 [S,m]=som_grid(lattice, [N 1],... | |
1221 'Coord',coord, ... | |
1222 'Line','none',... | |
1223 'Marker',marker,... | |
1224 'MarkerColor',color,... | |
1225 'MarkerSize', spotSize*Property.markersize); | |
1226 h_=[h_;m(:)]; | |
1227 case 'pie' | |
1228 h_(i)=som_pieplane(lattice, coord, ... | |
1229 Hits, Property.markercolor, ... | |
1230 totHits*Property.markersize); | |
1231 end | |
1232 | |
1233 % Restore hold state and caxis | |
1234 if ~memhold | |
1235 hold off; | |
1236 end | |
1237 caxis(cax); | |
1238 end | |
1239 | |
1240 % Set edgecolor | |
1241 if any(strcmp(mode,{'lattice','pie'})), | |
1242 set(h_,'edgecolor',Property.edgecolor); | |
1243 else | |
1244 set(h_,'markeredgecolor',Property.edgecolor); | |
1245 end | |
1246 | |
1247 %% Set object tags (for som_show_clear) %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1248 | |
1249 set(h_,'Tag','Hit') | |
1250 | |
1251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1252 | |
1253 function h_=label(Labels, lattice, msize, Property) | |
1254 | |
1255 % number of map units | |
1256 munits=prod(msize); | |
1257 | |
1258 % subplots and handles | |
1259 p=Property.subplot; | |
1260 handles= Property.handles; | |
1261 | |
1262 % Set default text size | |
1263 if isempty(Property.textsize) % default point size | |
1264 Property.textsize=10; | |
1265 end | |
1266 | |
1267 % Check color/set default | |
1268 if isempty(Property.textcolor), | |
1269 Property.textcolor='k'; | |
1270 end | |
1271 | |
1272 % handles will be collected in h_ for output | |
1273 h_=[]; | |
1274 | |
1275 %%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1276 | |
1277 for i=1:length(p); | |
1278 % set axes | |
1279 axes(handles(p(i))); | |
1280 % store hold state and caxis (for some reason matlab may | |
1281 % change caxis(!?) | |
1282 memhold=ishold; | |
1283 hold on; | |
1284 cax=caxis; | |
1285 | |
1286 % Write labels | |
1287 [S,m,l,t]=som_grid(lattice, msize, ... | |
1288 'Line','none', ... | |
1289 'Marker', 'none', ... | |
1290 'Label', Labels, ... | |
1291 'LabelColor', Property.textcolor, ... | |
1292 'LabelSize', Property.textsize); | |
1293 % Get handles | |
1294 h_=[h_;m(:);l(:);t(:)]; | |
1295 | |
1296 % reset hold state and caxis | |
1297 if ~memhold | |
1298 hold off; | |
1299 end | |
1300 caxis(cax); | |
1301 end | |
1302 | |
1303 %%% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1304 | |
1305 set(h_,'Tag','Lab'); | |
1306 | |
1307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1308 | |
1309 function h_=traj(bmu, lattice, msize, Property) | |
1310 | |
1311 % number of map units | |
1312 munits=prod(msize); | |
1313 | |
1314 % subplots and handles | |
1315 p=Property.subplot; | |
1316 handles=Property.handles; | |
1317 | |
1318 % Set default text color | |
1319 %if isempty(Property.textcolor), | |
1320 % Property.textcolor='k'; | |
1321 %end | |
1322 | |
1323 % Set default text size | |
1324 %if isempty(Property.textsize) | |
1325 % Property.textsize=10; | |
1326 %end | |
1327 | |
1328 % Set default marker | |
1329 if isempty(Property.marker) | |
1330 Property.marker='o'; | |
1331 end | |
1332 | |
1333 % Set default markersize | |
1334 if isempty(Property.markersize) | |
1335 Property.markersize=10; | |
1336 end | |
1337 | |
1338 % Set default markercolor | |
1339 if isempty(Property.markercolor) | |
1340 Property.markercolor='w'; | |
1341 end | |
1342 | |
1343 % Set default sizefactor | |
1344 if isempty(Property.sizefactor) | |
1345 %Property.sizefactor=0; | |
1346 Property.sizefactor='hit'; | |
1347 end | |
1348 | |
1349 % Set default trajwidth | |
1350 if isempty(Property.trajwidth) | |
1351 Property.trajwidth=3; | |
1352 end | |
1353 | |
1354 % Set default widthfactor | |
1355 if isempty(Property.widthfactor) | |
1356 Property.widthfactor='hit'; | |
1357 end | |
1358 | |
1359 % Set default trajcolor | |
1360 if isempty(Property.trajcolor) | |
1361 Property.trajcolor='w'; | |
1362 end | |
1363 | |
1364 % if no labels, do a empty cell array for syntax reasons | |
1365 %if isempty(Property.text), | |
1366 % Property.text=cell(munits,1); | |
1367 %end | |
1368 | |
1369 h_=[]; % handles will be collected in h_ for output | |
1370 l=length(bmu); % length of trajectory | |
1371 C=sparse(munits, munits); % init a connection matrix | |
1372 | |
1373 %%%%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1374 | |
1375 % Calculate the connection matrix that describes the trajectory | |
1376 for i=1:l-1, | |
1377 % The following if structure removes the possible redundancy due | |
1378 % to travels in both directions between two nodes of trajectory | |
1379 % (i.e. reflexivity) | |
1380 I=bmu(i+1);J=bmu(i); | |
1381 %if bmu(i)>bmu(i+1) | |
1382 | |
1383 %else | |
1384 % I=bmu(i);J=bmu(i+1); | |
1385 %end | |
1386 C(I,J)=C(I,J)+1; | |
1387 end | |
1388 | |
1389 % transitive connections are equal | |
1390 C=C+C'; | |
1391 % drop reflexive conncetions away | |
1392 C=spdiags(zeros(munits,1),0,C); | |
1393 | |
1394 % Do labels of trajectory nodes | |
1395 | |
1396 %traj_lab=cell(munits,1); | |
1397 hits=zeros(munits,1); | |
1398 | |
1399 for i=1:l, | |
1400 % traj_lab{bmu(i)}=strvcat(traj_lab{bmu(i)},Property.text{i}); | |
1401 hits(bmu(i))=(hits(bmu(i))+1); | |
1402 end | |
1403 | |
1404 % Calculate unit coordinates | |
1405 unit_coord=som_vis_coords(lattice, msize); | |
1406 | |
1407 % Calculate line width | |
1408 if strcmp(Property.widthfactor,'equal') | |
1409 TrajWidth=(C>0)*Property.trajwidth; | |
1410 else | |
1411 TrajWidth=Property.trajwidth.*sqrt(C./max(max(C))); | |
1412 end | |
1413 | |
1414 % Calculate marker sizes | |
1415 if strcmp(Property.sizefactor,'hit') | |
1416 MarkerSize=Property.markersize*sqrt(hits/max(hits)); | |
1417 else | |
1418 MarkerSize=Property.markersize*(hits>0); | |
1419 end | |
1420 | |
1421 for i=1:length(p), | |
1422 axes(handles(p(i))); | |
1423 % Get hold state and caxis | |
1424 memhold=ishold; cax=caxis; | |
1425 hold on; | |
1426 | |
1427 %'Label', traj_lab, ... | |
1428 %'LabelColor', Property.textcolor, ... | |
1429 %'LabelSize', Property.textsize, ... | |
1430 | |
1431 % Draw | |
1432 [S,m,l,t,s]=som_grid(C,msize,'coord',unit_coord,... | |
1433 'Line','-', ... | |
1434 'LineColor', Property.trajcolor, ... | |
1435 'LineWidth', TrajWidth, ... | |
1436 'Marker', Property.marker, ... | |
1437 'MarkerColor', Property.markercolor, ... | |
1438 'MarkerSize', MarkerSize); | |
1439 | |
1440 % Restore hold state and caxis | |
1441 if ~memhold | |
1442 hold off; | |
1443 end | |
1444 caxis(cax); | |
1445 % Get handles | |
1446 h_=[h_;m(:);l(:);t(:);s(:)]; | |
1447 end | |
1448 | |
1449 %% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1450 | |
1451 set(h_,'Tag','Traj'); | |
1452 | |
1453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1454 | |
1455 function h_=comet(bmu, lattice, msize, Property) | |
1456 | |
1457 % number of map units | |
1458 munits=prod(msize); | |
1459 | |
1460 % subplots and handles | |
1461 p=Property.subplot; | |
1462 handles=Property.handles; | |
1463 | |
1464 % Set default text color | |
1465 %if isempty(Property.textcolor), | |
1466 % Property.textcolor='k'; | |
1467 %end | |
1468 | |
1469 %% Set default text size | |
1470 %if isempty(Property.textsize) | |
1471 % Property.textsize=10; | |
1472 %end | |
1473 | |
1474 % Set default marker | |
1475 if isempty(Property.marker) | |
1476 Property.marker='o'; | |
1477 end | |
1478 | |
1479 % Set default markersize | |
1480 if isempty(Property.markersize), | |
1481 if strcmp(Property.marker,'lattice'), | |
1482 Property.markersize=linspace(0.8,0.1,length(bmu))'; | |
1483 else | |
1484 Property.markersize=sqrt(linspace(400,16,length(bmu)))'; | |
1485 end | |
1486 else | |
1487 if strcmp(Property.marker,'lattice'), | |
1488 Property.markersize=linspace(Property.markersize(1),... | |
1489 Property.markersize(2), ... | |
1490 length(bmu))'; | |
1491 else | |
1492 Property.markersize=sqrt(linspace(Property.markersize(1).^2,... | |
1493 Property.markersize(2).^2, ... | |
1494 length(bmu)))'; | |
1495 | |
1496 end | |
1497 end | |
1498 | |
1499 % Set default markercolor | |
1500 if isempty(Property.markercolor) | |
1501 Property.markercolor='w'; | |
1502 end | |
1503 | |
1504 % Set default edgecolor | |
1505 if isempty(Property.edgecolor), | |
1506 if vis_valuetype(Property.markercolor,{'nx3rgb'}), | |
1507 Property.edgecolor='none'; | |
1508 else | |
1509 Property.edgecolor=Property.markercolor; | |
1510 end | |
1511 end | |
1512 | |
1513 h_=[];l_=[]; % handles will be collected in h_ for output | |
1514 N_bmus=length(bmu); % length of trajectory | |
1515 | |
1516 % if no labels, do a empty cell array for syntax reasons | |
1517 %if isempty(Property.text), | |
1518 % Property.text=cell(N_bmus,1); | |
1519 %end | |
1520 | |
1521 %%%%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1522 | |
1523 % Calculate unit coordinates for trajectory points | |
1524 unit_coord=som_vis_coords(lattice, msize); | |
1525 coord=unit_coord(bmu,:); | |
1526 | |
1527 % Make labels for the _unique_ units that the comet hits | |
1528 | |
1529 unique_bmu=unique(bmu); % count units | |
1530 %N_labels=length(unique_bmu); | |
1531 %traj_lab=cell(N_labels,1); % cell for labels | |
1532 %label_coord=unit_coord(unique_bmu,:); % label coordinates | |
1533 | |
1534 % Make labels | |
1535 %for i=1:N_bmus, | |
1536 % index=find(unique_bmu==bmu(i)); | |
1537 % traj_lab{index}=strvcat(traj_lab{index},Property.text{i}); | |
1538 %end | |
1539 | |
1540 %Main loop for drawing comets | |
1541 for i=1:length(p), | |
1542 % set axis | |
1543 axes(handles(p(i))); | |
1544 | |
1545 % Get hold state and caxis | |
1546 memhold=ishold; cax=caxis; | |
1547 hold on; | |
1548 | |
1549 if strcmp(Property.marker,'lattice'), | |
1550 % Draw: marker is a patch ('hexa','rect') | |
1551 l_=som_cplane(lattice, coord, Property.markercolor, ... | |
1552 Property.markersize); | |
1553 | |
1554 % Set edgecolor | |
1555 set(l_,'edgecolor',Property.edgecolor); | |
1556 else | |
1557 % Draw: other markers than 'hexa' or 'rect' | |
1558 [S,m,l,t,s]=som_grid(lattice, [N_bmus 1], 'coord', coord,... | |
1559 'Line','none', ... | |
1560 'Marker', Property.marker, ... | |
1561 'MarkerColor', Property.markercolor, ... | |
1562 'MarkerSize',Property.markersize); | |
1563 | |
1564 % Set edgecolor | |
1565 set(m, 'markeredgecolor', Property.edgecolor); | |
1566 | |
1567 % Get handles from markers | |
1568 h_=[h_;l_(:);m(:);l(:);t(:);s(:)]; | |
1569 end | |
1570 | |
1571 % Set labels | |
1572 %[S,m,l,t,s]=som_grid(lattice, [N_labels 1], 'coord', label_coord,... | |
1573 % 'Marker','none','Line','none',... | |
1574 % 'Label', traj_lab, ... | |
1575 % 'LabelColor', Property.textcolor, ... | |
1576 % 'LabelSize', Property.textsize); | |
1577 % Get handles from labels | |
1578 %h_=[h_;m(:);l(:);t(:);s(:)]; | |
1579 | |
1580 % Restore hold state and caxis | |
1581 if ~memhold | |
1582 hold off; | |
1583 end | |
1584 caxis(cax); | |
1585 end | |
1586 | |
1587 %% Set object tags %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1588 | |
1589 set(h_,'Tag','Comet'); | |
1590 | |
1591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
1592 | |
1593 | |
1594 function P=init_properties; | |
1595 | |
1596 % Initialize an empty property struct | |
1597 | |
1598 P.marker=[]; | |
1599 P.markersize=[]; | |
1600 P.sizefactor=[]; | |
1601 P.markercolor=[]; | |
1602 P.edgecolor=[]; | |
1603 P.trajwidth=[]; | |
1604 P.widthfactor=[]; | |
1605 P.trajcolor=[]; | |
1606 P.text=[]; | |
1607 P.textsize=[]; | |
1608 P.textcolor=[]; | |
1609 P.subplot=[]; | |
1610 P.shift=[]; |