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

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