wolffd@0: function ind = som_cod2ind(msize,cind) wolffd@0: wolffd@0: %SOM_COD2IND Matlab linear index from SOM_PAK style linear indeces. wolffd@0: % wolffd@0: % ind = som_cod2ind(msize,cind) wolffd@0: % wolffd@0: % ind = som_cod2ind([10 15],44); wolffd@0: % ind = som_cod2ind(sMap,44); wolffd@0: % ind = som_cod2ind(sMap.msize,44); wolffd@0: % ind = som_cod2ind([10 15],[44 13 91]'); wolffd@0: % wolffd@0: % Input and output arguments: wolffd@0: % msize (struct) map or topology struct wolffd@0: % (vector) size 1 x m, specifies the map grid size wolffd@0: % cind (vector) size n x 1, SOM_PAK style linear indeces for n map units wolffd@0: % (row first, then column) wolffd@0: % wolffd@0: % ind (vector) size n x 1, Matlab linear indeces wolffd@0: % wolffd@0: % See also SOM_IND2COD. wolffd@0: wolffd@0: % Contributed to SOM Toolbox vs2, January 14th, 2002 by Juha Vesanto wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta juuso 140102 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: if isstruct(msize), wolffd@0: if strcmp(msize.type,'som_map'), msize = msize.topol.msize; wolffd@0: elseif strcmp(msize.type,'som_topol'), msize = msize.msize; wolffd@0: else error('Invalid first argument.'); end wolffd@0: end wolffd@0: wolffd@0: if nargin<2, cind = 1:prod(msize); end wolffd@0: wolffd@0: I2C = som_ind2cod(msize,[1:prod(msize)]); wolffd@0: [dummy,C2I] = sort(I2C); wolffd@0: ind = C2I(cind); wolffd@0: wolffd@0: return; wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%