Mercurial > hg > octave-lyh
diff scripts/statistics/base/std.m @ 12781:645a87434fcb
std.m: Allow null inputs []. Bug #33532.
* std.m: Allow null inputs []. Bug #33532.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 13 Jul 2011 17:43:30 -0700 |
parents | 6b2f14af2360 |
children | 72c96de7a403 |
line wrap: on
line diff
--- a/scripts/statistics/base/std.m +++ b/scripts/statistics/base/std.m @@ -91,16 +91,14 @@ endif n = sz(dim); - if (n == 1) + if (n == 1 || isempty (x)) if (isa (x, 'single')) retval = zeros (sz, 'single'); else retval = zeros (sz); endif - elseif (numel (x) > 0) + else retval = sqrt (sumsq (center (x, dim), dim) / (n - 1 + opt)); - else - error ("std: X must not be empty"); endif endfunction @@ -118,11 +116,12 @@ %!assert(std ([1 2], 1), 0.5, 5*eps); %!assert(std(1), 0); %!assert(std(single(1)), single(0)); +%!assert(std([]), []); +%!assert(std(ones (1,3,0,2)), ones (1,3,0,2)); %% Test input validation %!error std (); %!error std (1, 2, 3, 4); %!error std (['A'; 'B']) %!error std (1, -1); -%!error std ([], 1);