Mercurial > hg > octave-nkf
comparison scripts/statistics/base/var.m @ 8977:f464119ec165
further simplify some stats funcs
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 13 Mar 2009 21:26:13 +0100 |
parents | a1dbe9d80eee |
children | 80d499b82ff3 |
comparison
equal
deleted
inserted
replaced
8976:22a7e4690742 | 8977:f464119ec165 |
---|---|
54 endif | 54 endif |
55 if (nargin < 2 || isempty (opt)) | 55 if (nargin < 2 || isempty (opt)) |
56 opt = 0; | 56 opt = 0; |
57 endif | 57 endif |
58 | 58 |
59 sz = size (x); | 59 n = size (a, dim); |
60 if (prod (sz) < 1) | 60 if (n == 1) |
61 retval = zeros (sz); | |
62 elseif (numel (a) > 0) | |
63 retval = sumsq (center (a, dim), dim) / (n + opt - 1); | |
64 else | |
61 error ("var: x must not be empty"); | 65 error ("var: x must not be empty"); |
62 elseif (sz(dim) == 1) | |
63 y = 0; | |
64 else | |
65 rng = ones (1, length (sz)); | |
66 rng (dim) = sz (dim); | |
67 if (opt == 0) | |
68 y = sumsq (x - repmat(mean (x, dim), rng), dim) / (sz(dim) - 1); | |
69 else | |
70 y = sumsq (x - repmat(mean (x, dim), rng), dim) / sz(dim); | |
71 endif | |
72 endif | 66 endif |
73 | 67 |
74 endfunction | 68 endfunction |