annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_ind2cod.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function cind = som_ind2cod(msize,ind)
Daniel@0 2
Daniel@0 3 %SOM_IND2COD SOM_PAK style linear indeces from Matlab linear index.
Daniel@0 4 %
Daniel@0 5 % Cind = som_ind2cod(msize,inds)
Daniel@0 6 %
Daniel@0 7 % cind = som_ind2cod([10 15],44);
Daniel@0 8 % cind = som_ind2cod(sMap,44);
Daniel@0 9 % cind = som_ind2cod(sMap.msize,44);
Daniel@0 10 % Cind = som_ind2cod([10 15],[44 13 91]');
Daniel@0 11 %
Daniel@0 12 % Input and output arguments:
Daniel@0 13 % msize (struct) map or topology struct
Daniel@0 14 % (vector) size 1 x m, specifies the map grid size
Daniel@0 15 % ind (vector) size n x 1, linear indeces of n map units
Daniel@0 16 %
Daniel@0 17 % cind (matrix) size n x 1, SOM_PAK style linear indeces
Daniel@0 18 % (row first, then column)
Daniel@0 19 %
Daniel@0 20 % See also SOM_COD2IND.
Daniel@0 21
Daniel@0 22 % Contributed to SOM Toolbox vs2, January 14th, 2002 by Juha Vesanto
Daniel@0 23 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 24
Daniel@0 25 % Version 2.0beta juuso 140102
Daniel@0 26
Daniel@0 27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 28
Daniel@0 29 if isstruct(msize),
Daniel@0 30 if strcmp(msize.type,'som_map'), msize = msize.topol.msize;
Daniel@0 31 elseif strcmp(msize.type,'som_topol'), msize = msize.msize;
Daniel@0 32 else error('Invalid first argument.'); end
Daniel@0 33 end
Daniel@0 34
Daniel@0 35 if nargin<2, ind = 1:prod(msize); end
Daniel@0 36
Daniel@0 37 Co = som_unit_coords(msize,'rect','sheet');
Daniel@0 38
Daniel@0 39 switch size(Co,2),
Daniel@0 40 case 1, I2C = [1:prod(msize)];
Daniel@0 41 case 2, I2C = 1 + Co(:,1) + Co(:,2)*msize(2);
Daniel@0 42 case 3, I2C = 1 + Co(:,1) + Co(:,2)*msize(2) + Co(:,3)*msize(1)*msize(2); % ?????
Daniel@0 43 end
Daniel@0 44
Daniel@0 45 cind = I2C(ind);
Daniel@0 46 return;
Daniel@0 47
Daniel@0 48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%