comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/nanstats.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 [me, st, md, no] = nanstats(D)
2
3 %NANSTATS Statistical operations that ignore NaNs and Infs.
4 %
5 % [mean, std, median, nans] = nanstats(D)
6 %
7 % Input and output arguments:
8 % D (struct) data or map struct
9 % (matrix) size dlen x dim
10 %
11 % me (double) columnwise mean
12 % st (double) columnwise standard deviation
13 % md (double) columnwise median
14 % no (vector) columnwise number of samples (finite, not-NaN)
15
16 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Vesanto
17 % http://www.cis.hut.fi/projects/somtoolbox/
18
19 % Version 2.0beta juuso 300798 200900
20
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %% check arguments
23
24 (nargchk(1, 1, nargin)); % check no. of input args is correct
25
26 if isstruct(D),
27 if strcmp(D.type,'som_map'), D = D.codebook;
28 else D = D.data;
29 end
30 end
31 [dlen dim] = size(D);
32 me = zeros(dim,1)+NaN;
33 md = me;
34 st = me;
35 no = me;
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %% computation
39
40 for i = 1:dim,
41 ind = find(isfinite(D(:, i))); % indices of non-NaN/Inf elements
42 n = length(ind); % no of non-NaN/Inf elements
43
44 me(i) = sum(D(ind, i)); % compute average
45 if n == 0, me(i) = NaN; else me(i) = me(i) / n; end
46
47 if nargout>1,
48 md(i) = median(D(ind, i)); % compute median
49
50 if nargout>2,
51 st(i) = sum((me(i) - D(ind, i)).^2); % compute standard deviation
52 if n == 0, st(i) = NaN;
53 elseif n == 1, st(i) = 0;
54 else st(i) = sqrt(st(i) / (n - 1));
55 end
56
57 if nargout>3,
58 no(i) = n; % number of samples (finite, not-NaN)
59 end
60 end
61 end
62 end
63
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65