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