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