wolffd@0
|
1 function inds = som_sub2ind(msize,Subs)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_SUB2IND Linear index from map grid subscripts.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % ind = som_sub2ind(msize,Subs)
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % ind = som_sub2ind([10 15],[4 5]);
|
wolffd@0
|
8 % ind = som_sub2ind(sMap,[4 5]);
|
wolffd@0
|
9 % ind = som_sub2ind(sMap.msize,[4 5]);
|
wolffd@0
|
10 % inds = som_sub2ind([10 15],[4 5; 3 2; 1 10]);
|
wolffd@0
|
11 %
|
wolffd@0
|
12 % Input and output arguments:
|
wolffd@0
|
13 % msize (struct) map or topology struct
|
wolffd@0
|
14 % (vector) size 1 x m, specifies the map grid size
|
wolffd@0
|
15 % Subs (matrix) size n x m, the subscripts of n vectors
|
wolffd@0
|
16 %
|
wolffd@0
|
17 % inds (vector) size n x 1, corresponding linear indeces
|
wolffd@0
|
18 %
|
wolffd@0
|
19 % See also SOM_IND2SUB.
|
wolffd@0
|
20
|
wolffd@0
|
21 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Vesanto
|
wolffd@0
|
22 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
23
|
wolffd@0
|
24 % juuso 300798
|
wolffd@0
|
25
|
wolffd@0
|
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
27
|
wolffd@0
|
28 if isstruct(msize),
|
wolffd@0
|
29 if strcmp(msize.type,'som_map'), msize = msize.topol.msize;
|
wolffd@0
|
30 elseif strcmp(msize.type,'som_topol'), msize = msize.msize;
|
wolffd@0
|
31 else error('Invalid first argument.'); end
|
wolffd@0
|
32 end
|
wolffd@0
|
33
|
wolffd@0
|
34 % check off-limits
|
wolffd@0
|
35 [n d] = size(Subs);
|
wolffd@0
|
36 offl = find(Subs < 1 | Subs > msize(ones(n,1),1:d));
|
wolffd@0
|
37 Subs(offl) = NaN;
|
wolffd@0
|
38
|
wolffd@0
|
39 % indexes
|
wolffd@0
|
40 k = [1 cumprod(msize(1:end-1))]';
|
wolffd@0
|
41 inds = 1 + (Subs-1)*k;
|
wolffd@0
|
42
|
wolffd@0
|
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|