# HG changeset patch # User Rik # Date 1310604210 25200 # Node ID 645a87434fcb97868281b57435aa3ec840092af6 # Parent c99714aeb00850dffa1b419ba53bb3463da6c257 std.m: Allow null inputs []. Bug #33532. * std.m: Allow null inputs []. Bug #33532. diff --git a/scripts/statistics/base/std.m b/scripts/statistics/base/std.m --- 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);