comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_ind2cod.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 cind = som_ind2cod(msize,ind)
2
3 %SOM_IND2COD SOM_PAK style linear indeces from Matlab linear index.
4 %
5 % Cind = som_ind2cod(msize,inds)
6 %
7 % cind = som_ind2cod([10 15],44);
8 % cind = som_ind2cod(sMap,44);
9 % cind = som_ind2cod(sMap.msize,44);
10 % Cind = som_ind2cod([10 15],[44 13 91]');
11 %
12 % Input and output arguments:
13 % msize (struct) map or topology struct
14 % (vector) size 1 x m, specifies the map grid size
15 % ind (vector) size n x 1, linear indeces of n map units
16 %
17 % cind (matrix) size n x 1, SOM_PAK style linear indeces
18 % (row first, then column)
19 %
20 % See also SOM_COD2IND.
21
22 % Contributed to SOM Toolbox vs2, January 14th, 2002 by Juha Vesanto
23 % http://www.cis.hut.fi/projects/somtoolbox/
24
25 % Version 2.0beta juuso 140102
26
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
29 if isstruct(msize),
30 if strcmp(msize.type,'som_map'), msize = msize.topol.msize;
31 elseif strcmp(msize.type,'som_topol'), msize = msize.msize;
32 else error('Invalid first argument.'); end
33 end
34
35 if nargin<2, ind = 1:prod(msize); end
36
37 Co = som_unit_coords(msize,'rect','sheet');
38
39 switch size(Co,2),
40 case 1, I2C = [1:prod(msize)];
41 case 2, I2C = 1 + Co(:,1) + Co(:,2)*msize(2);
42 case 3, I2C = 1 + Co(:,1) + Co(:,2)*msize(2) + Co(:,3)*msize(1)*msize(2); % ?????
43 end
44
45 cind = I2C(ind);
46 return;
47
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%