changeset 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 c99714aeb008
children 9d5e468befe5
files scripts/statistics/base/std.m
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/statistics/base/std.m	Wed Jul 13 17:28:26 2011 -0700
+++ b/scripts/statistics/base/std.m	Wed Jul 13 17:43:30 2011 -0700
@@ -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);