Daniel@0: function Subs = som_ind2sub(msize,inds) Daniel@0: Daniel@0: %SOM_IND2SUB Map grid subscripts from linear index. Daniel@0: % Daniel@0: % Subs = som_ind2sub(msize,inds) Daniel@0: % Daniel@0: % sub = som_ind2sub([10 15],44); Daniel@0: % sub = som_ind2sub(sMap,44); Daniel@0: % sub = som_ind2sub(sMap.msize,44); Daniel@0: % Subs = som_ind2sub([10 15],[44 13 91]'); Daniel@0: % Daniel@0: % Input and output arguments: Daniel@0: % msize (struct) map or topology struct Daniel@0: % (vector) size 1 x m, specifies the map grid size Daniel@0: % inds (vector) size n x 1, linear indeces of n map units Daniel@0: % Daniel@0: % Subs (matrix) size n x m, the subscripts Daniel@0: % Daniel@0: % See also SOM_SUB2IND. Daniel@0: Daniel@0: % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 300798 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: if isstruct(msize), Daniel@0: if strcmp(msize.type,'som_map'), msize = msize.topol.msize; Daniel@0: elseif strcmp(msize.type,'som_topol'), msize = msize.msize; Daniel@0: else error('Invalid first argument.'); end Daniel@0: end Daniel@0: Daniel@0: n = length(msize); Daniel@0: k = [1 cumprod(msize(1:end-1))]; Daniel@0: inds = inds - 1; Daniel@0: for i = n:-1:1, Daniel@0: Subs(:,i) = floor(inds/k(i))+1; Daniel@0: inds = rem(inds,k(i)); Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%