annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_bmucolor.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function bmu_colors=som_bmucolor(bmus, m, colors);
wolffd@0 2
wolffd@0 3 % SOM_BMUCOLOR Returns the colors of the bmus according to a map colorcode
wolffd@0 4 %
wolffd@0 5 % bmu_colors=som_bmucolor(bmus, msize, colors);
wolffd@0 6 %
wolffd@0 7 % INPUT ARGUMENTS ([]'s are optional)
wolffd@0 8 %
wolffd@0 9 % bmus (matrix) Nx1 vector of BMU indexes
wolffd@0 10 % msize (map struct, topol struct or 1x2 vector)
wolffd@0 11 % gives the map grid size
wolffd@0 12 % colors (matrix) colormap(s): munits x 3 x d matrix of RGB vectors
wolffd@0 13 %
wolffd@0 14 % OUTPUT ARGUMENTS
wolffd@0 15 %
wolffd@0 16 % bmu_colors (Nx3xd matrix) color of the data point according to its BMU's
wolffd@0 17 % color(s).
wolffd@0 18 %
wolffd@0 19 % Idea is to get a color for each data point that links it to its BMU.
wolffd@0 20 %
wolffd@0 21 % EXAMPLE
wolffd@0 22 %
wolffd@0 23 % We want to show how an time series is projected to a map. Instead of
wolffd@0 24 % a trajectory, we use 'color linking'
wolffd@0 25 %
wolffd@0 26 % map=som_make(multi_dim_signal);
wolffd@0 27 % bmus=som_bmu(map,multi_dim_signal);
wolffd@0 28 % Colors=som_bmucolor(bmus, map, som_colorcode(map,'rgb1'));
wolffd@0 29 % colorsignal(Colors, multi_dim_signal);
wolffd@0 30 %
wolffd@0 31 % See also SOM_COLORCODE.
wolffd@0 32
wolffd@0 33 % Copyright (c) 1999-2000 by the SOM toolbox programming team.
wolffd@0 34 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 35
wolffd@0 36 % Version 2.0alpha Johan 170699
wolffd@0 37
wolffd@0 38 %% Check arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 39
wolffd@0 40 error(nargchk(3, 3, nargin)) % check no. of input args is correct
wolffd@0 41
wolffd@0 42 % Check map grid size
wolffd@0 43
wolffd@0 44 if vis_valuetype(m,{'1x2'}),
wolffd@0 45 msize=m;
wolffd@0 46 else
wolffd@0 47 [tmp,ok,tmp]=som_set(m);
wolffd@0 48 if isstruct(m) & all(ok) % check m type
wolffd@0 49 switch m.type
wolffd@0 50 case 'som_topol'
wolffd@0 51 msize=m.msize;
wolffd@0 52 lattice=m.lattice;
wolffd@0 53 case 'som_map'
wolffd@0 54 msize=m.topol.msize;
wolffd@0 55 lattice=m.topol.lattice;
wolffd@0 56 otherwise
wolffd@0 57 error('Invalid map or topol struct.');
wolffd@0 58 end
wolffd@0 59 end
wolffd@0 60 end
wolffd@0 61
wolffd@0 62 if length(msize)>2
wolffd@0 63 error('Only 2D maps allowed!');
wolffd@0 64 end
wolffd@0 65
wolffd@0 66 n=prod(msize)
wolffd@0 67
wolffd@0 68 % Check colorcode size
wolffd@0 69
wolffd@0 70 if ~vis_valuetype(colors,{'nx3xdimrgb','nx3rgb'})
wolffd@0 71 error('Colorcode matrix not valid!');
wolffd@0 72 end
wolffd@0 73
wolffd@0 74 % Check bmu vector
wolffd@0 75
wolffd@0 76 if ~vis_valuetype(bmus,{'nx1'}),
wolffd@0 77 error('Need a column vector of BMU indexes!');
wolffd@0 78 else
wolffd@0 79 bmus=round(bmus);
wolffd@0 80 if max(bmus) > n | min(bmus) < 1
wolffd@0 81 error('BMU indexes exeed the map size!')
wolffd@0 82 end
wolffd@0 83 end
wolffd@0 84
wolffd@0 85 %% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 86
wolffd@0 87 bmu_c=colors(bmus,:,:);
wolffd@0 88
wolffd@0 89 %% Build output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 90
wolffd@0 91
wolffd@0 92 bmu_colors=squeeze(bmu_c);
wolffd@0 93