comparison scripts/statistics/base/std.m @ 8977:f464119ec165

further simplify some stats funcs
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 13 Mar 2009 21:26:13 +0100
parents eb63fbe60fab
children 1bf0ce0930be
comparison
equal deleted inserted replaced
8976:22a7e4690742 8977:f464119ec165
74 endif 74 endif
75 if (nargin < 2 || isempty (opt)) 75 if (nargin < 2 || isempty (opt))
76 opt = 0; 76 opt = 0;
77 endif 77 endif
78 78
79 sz = size(a); 79 n = size (a, dim);
80 if (sz (dim) == 1) 80 if (n == 1)
81 retval = zeros(sz); 81 retval = zeros (sz);
82 elseif (numel (a) > 0) 82 elseif (numel (a) > 0)
83 rng = ones (1, length (sz)); 83 retval = sqrt (sumsq (center (a, dim), dim) / (n + opt - 1));
84 rng (dim) = sz (dim);
85 if (opt == 0)
86 retval = sqrt (sumsq (a - repmat(mean (a, dim), rng), dim) / (sz(dim) - 1));
87 else
88 retval = sqrt (sumsq (a - repmat(mean (a, dim), rng), dim) / sz(dim));
89 endif
90 else 84 else
91 error ("std: invalid matrix argument"); 85 error ("std: x must not be empty");
92 endif 86 endif
93 87
94 endfunction 88 endfunction
95 89
96 %!test 90 %!test