Mercurial > hg > camir-aes2014
diff toolboxes/MIRtoolbox1.3.2/somtoolbox/som_fillnans.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolboxes/MIRtoolbox1.3.2/somtoolbox/som_fillnans.m Tue Feb 10 15:05:51 2015 +0000 @@ -0,0 +1,56 @@ +function sD = som_fillnans(sD,sM,bmus) + +% SOM_FILLNANS Replaces NaNs in the data matrix with values from +% SOM prototypes. +% +% sD = som_fillnans(sD,sM, [bmus]) +% +% sD (struct) data struct +% (matrix) size dlen x dim +% sM (struct) data struct, with .data of size dlen x dim +% (matrix) size dlen x dim, a matrix from which +% the values are taken from directly +% (struct) map struct: replacement values are taken from +% sM.codebook(bmus,:) +% [bmus] (vector) BMU for each data vector (calculated if not specified) +% +% See also SOM_MAKE. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if isstruct(sD), + [dlen dim] = size(sD.data); + nans = find(isnan(sD.data)); +else + [dlen dim] = size(sD); + nans = find(isnan(sD)); +end + +if nargin<3, + bmus = som_bmus(sM,sD); +end + +if isstruct(sM) & strcmp(sM.type,'som_map'), + sM = sM.codebook(bmus,:); +elseif isstruct(sM), + sM = sM.data(bmus,:); +else + sM = sM(bmus,:); +end +me = mean(sM); + +if any(size(sM) ~= [dlen dim]), + error('Invalid input arguments.') +end + +if isstruct(sD), + sD.data(nans) = sM(nans); +else + sD(nans) = sM(nans); +end + +return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +