Daniel@0: function ind = som_cod2ind(msize,cind) Daniel@0: Daniel@0: %SOM_COD2IND Matlab linear index from SOM_PAK style linear indeces. Daniel@0: % Daniel@0: % ind = som_cod2ind(msize,cind) Daniel@0: % Daniel@0: % ind = som_cod2ind([10 15],44); Daniel@0: % ind = som_cod2ind(sMap,44); Daniel@0: % ind = som_cod2ind(sMap.msize,44); Daniel@0: % ind = som_cod2ind([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: % cind (vector) size n x 1, SOM_PAK style linear indeces for n map units Daniel@0: % (row first, then column) Daniel@0: % Daniel@0: % ind (vector) size n x 1, Matlab linear indeces Daniel@0: % Daniel@0: % See also SOM_IND2COD. Daniel@0: Daniel@0: % Contributed to SOM Toolbox vs2, January 14th, 2002 by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 140102 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: if nargin<2, cind = 1:prod(msize); end Daniel@0: Daniel@0: I2C = som_ind2cod(msize,[1:prod(msize)]); Daniel@0: [dummy,C2I] = sort(I2C); Daniel@0: ind = C2I(cind); Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%