annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_fillnans.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 sD = som_fillnans(sD,sM,bmus)
Daniel@0 2
Daniel@0 3 % SOM_FILLNANS Replaces NaNs in the data matrix with values from
Daniel@0 4 % SOM prototypes.
Daniel@0 5 %
Daniel@0 6 % sD = som_fillnans(sD,sM, [bmus])
Daniel@0 7 %
Daniel@0 8 % sD (struct) data struct
Daniel@0 9 % (matrix) size dlen x dim
Daniel@0 10 % sM (struct) data struct, with .data of size dlen x dim
Daniel@0 11 % (matrix) size dlen x dim, a matrix from which
Daniel@0 12 % the values are taken from directly
Daniel@0 13 % (struct) map struct: replacement values are taken from
Daniel@0 14 % sM.codebook(bmus,:)
Daniel@0 15 % [bmus] (vector) BMU for each data vector (calculated if not specified)
Daniel@0 16 %
Daniel@0 17 % See also SOM_MAKE.
Daniel@0 18
Daniel@0 19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 20
Daniel@0 21 if isstruct(sD),
Daniel@0 22 [dlen dim] = size(sD.data);
Daniel@0 23 nans = find(isnan(sD.data));
Daniel@0 24 else
Daniel@0 25 [dlen dim] = size(sD);
Daniel@0 26 nans = find(isnan(sD));
Daniel@0 27 end
Daniel@0 28
Daniel@0 29 if nargin<3,
Daniel@0 30 bmus = som_bmus(sM,sD);
Daniel@0 31 end
Daniel@0 32
Daniel@0 33 if isstruct(sM) & strcmp(sM.type,'som_map'),
Daniel@0 34 sM = sM.codebook(bmus,:);
Daniel@0 35 elseif isstruct(sM),
Daniel@0 36 sM = sM.data(bmus,:);
Daniel@0 37 else
Daniel@0 38 sM = sM(bmus,:);
Daniel@0 39 end
Daniel@0 40 me = mean(sM);
Daniel@0 41
Daniel@0 42 if any(size(sM) ~= [dlen dim]),
Daniel@0 43 error('Invalid input arguments.')
Daniel@0 44 end
Daniel@0 45
Daniel@0 46 if isstruct(sD),
Daniel@0 47 sD.data(nans) = sM(nans);
Daniel@0 48 else
Daniel@0 49 sD(nans) = sM(nans);
Daniel@0 50 end
Daniel@0 51
Daniel@0 52 return;
Daniel@0 53
Daniel@0 54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 55
Daniel@0 56