# HG changeset patch
# User Nicholas R. Jankowski <jankowskin@asme.org>
# Date 1471290120 14400
#      Mon Aug 15 15:42:00 2016 -0400
# Node ID 82b3e8c7e0b638df0a4d64c22e6bc740bdbfc12d
# Parent  47af4546e62d0af04a9b7435b02a61115f4bfde8
Edited std.m so that emtpy input produces NaN with appropriate size, preserving single or double (bug #48690)

diff -r 47af4546e62d -r 82b3e8c7e0b6 scripts/statistics/base/std.m
--- a/scripts/statistics/base/std.m	Mon Aug 15 15:40:31 2016 -0400
+++ b/scripts/statistics/base/std.m	Mon Aug 15 15:42:00 2016 -0400
@@ -91,12 +91,30 @@
   endif
 
   n = size (x, dim);
-  if (n == 1 || isempty (x))
+  if (isempty (x))
+    %% codepath for Matlab Compatibility. empty x produces NaN output, but 
+    %% for ndim > 2, output depends on size of x.  tests include for
+    %% compatibility with Matlab 2016a, includes all empty arrays up to dim4,
+    %% sizes of 0 1 or 2 in each dim.
+    %% TODO:  update this if later Matlab versions show more output consistency
+    if ((nd == 2) && (max (sz) < 2))
+      retval = NaN;
+    else
+      sz (find ((sz ~= 1), 1)) = 1;
+      retval = NaN (sz);
+    endif
+
+    if (isa (x, "single"))
+        retval = single (retval);  
+    endif
+    
+  elseif (n == 1)
     if (isa (x, "single"))
       retval = zeros (sz, "single");
     else
       retval = zeros (sz);
     endif
+  
   else
     retval = sqrt (sumsq (center (x, dim), dim) / (n - 1 + opt));
   endif
@@ -116,10 +134,85 @@
 %!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))
 %!assert (std ([1 2 3], [], 3), [0 0 0])
 
+##tests for empty input matlab compatibility (v2016a)
+%!assert (std ([]), NaN)
+%!assert (std (single([])), single(NaN))
+
+%!assert (std (ones (0,0,0,0)), NaN (1,0,0,0))
+%!assert (std (ones (0,0,0,1)), NaN (1,0,0,1))
+%!assert (std (ones (0,0,0,2)), NaN (1,0,0,2))
+%!assert (std (ones (0,0,1,0)), NaN (1,0,1,0))
+%!assert (std (ones (0,0,1,1)), NaN (1,1,1,1))
+%!assert (std (ones (0,0,1,2)), NaN (1,0,1,2))
+%!assert (std (ones (0,0,2,0)), NaN (1,0,2,0))
+%!assert (std (ones (0,0,2,1)), NaN (1,0,2,1))
+%!assert (std (ones (0,0,2,2)), NaN (1,0,2,2))
+%!assert (std (ones (0,1,0,0)), NaN (1,1,0,0))
+%!assert (std (ones (0,1,0,1)), NaN (1,1,0,1))
+%!assert (std (ones (0,1,0,2)), NaN (1,1,0,2))
+%!assert (std (ones (0,1,1,0)), NaN (1,1,1,0))
+%!assert (std (ones (0,1,1,1)), NaN (1,1,1,1))
+%!assert (std (ones (0,1,1,2)), NaN (1,1,1,2))
+%!assert (std (ones (0,1,2,0)), NaN (1,1,2,0))
+%!assert (std (ones (0,1,2,1)), NaN (1,1,2,1))
+%!assert (std (ones (0,1,2,2)), NaN (1,1,2,2))
+%!assert (std (ones (0,2,0,0)), NaN (1,2,0,0))
+%!assert (std (ones (0,2,0,1)), NaN (1,2,0,1))
+%!assert (std (ones (0,2,0,2)), NaN (1,2,0,2))
+%!assert (std (ones (0,2,1,0)), NaN (1,2,1,0))
+%!assert (std (ones (0,2,1,1)), NaN (1,2,1,1))
+%!assert (std (ones (0,2,1,2)), NaN (1,2,1,2))
+%!assert (std (ones (0,2,2,0)), NaN (1,2,2,0))
+%!assert (std (ones (0,2,2,1)), NaN (1,2,2,1))
+%!assert (std (ones (0,2,2,2)), NaN (1,2,2,2))
+%!assert (std (ones (1,0,0,0)), NaN (1,1,0,0))
+%!assert (std (ones (1,0,0,1)), NaN (1,1,0,1))
+%!assert (std (ones (1,0,0,2)), NaN (1,1,0,2))
+%!assert (std (ones (1,0,1,0)), NaN (1,1,1,0))
+%!assert (std (ones (1,0,1,1)), NaN (1,1,1,1))
+%!assert (std (ones (1,0,1,2)), NaN (1,1,1,2))
+%!assert (std (ones (1,0,2,0)), NaN (1,1,2,0))
+%!assert (std (ones (1,0,2,1)), NaN (1,1,2,1))
+%!assert (std (ones (1,0,2,2)), NaN (1,1,2,2))
+%!assert (std (ones (1,1,0,0)), NaN (1,1,1,0))
+%!assert (std (ones (1,1,0,1)), NaN (1,1,1,1))
+%!assert (std (ones (1,1,0,2)), NaN (1,1,1,2))
+%!assert (std (ones (1,1,1,0)), NaN (1,1,1,1))
+%!assert (std (ones (1,1,2,0)), NaN (1,1,1,0))
+%!assert (std (ones (1,2,0,0)), NaN (1,1,0,0))
+%!assert (std (ones (1,2,0,1)), NaN (1,1,0,1))
+%!assert (std (ones (1,2,0,2)), NaN (1,1,0,2))
+%!assert (std (ones (1,2,1,0)), NaN (1,1,1,0))
+%!assert (std (ones (1,2,2,0)), NaN (1,1,2,0))
+%!assert (std (ones (2,0,0,0)), NaN (1,0,0,0))
+%!assert (std (ones (2,0,0,1)), NaN (1,0,0,1))
+%!assert (std (ones (2,0,0,2)), NaN (1,0,0,2))
+%!assert (std (ones (2,0,1,0)), NaN (1,0,1,0))
+%!assert (std (ones (2,0,1,1)), NaN (1,0,1,1))
+%!assert (std (ones (2,0,1,2)), NaN (1,0,1,2))
+%!assert (std (ones (2,0,2,0)), NaN (1,0,2,0))
+%!assert (std (ones (2,0,2,1)), NaN (1,0,2,1))
+%!assert (std (ones (2,0,2,2)), NaN (1,0,2,2))
+%!assert (std (ones (2,1,0,0)), NaN (1,1,0,0))
+%!assert (std (ones (2,1,0,1)), NaN (1,1,0,1))
+%!assert (std (ones (2,1,0,2)), NaN (1,1,0,2))
+%!assert (std (ones (2,1,1,0)), NaN (1,1,1,0))
+%!assert (std (ones (2,1,2,0)), NaN (1,1,2,0))
+%!assert (std (ones (2,2,0,0)), NaN (1,2,0,0))
+%!assert (std (ones (2,2,0,1)), NaN (1,2,0,1))
+%!assert (std (ones (2,2,0,2)), NaN (1,2,0,2))
+%!assert (std (ones (2,2,1,0)), NaN (1,2,1,0))
+%!assert (std (ones (2,2,2,0)), NaN (1,2,2,0))
+%!assert (std (ones(1,1,0,0,0)), NaN (1,1,1,0,0))
+%!assert (std (ones(1,1,1,1,0)), NaN (1,1,1,1,1))
+%!assert (std (ones(2,1,1,1,0)), NaN (1,1,1,1,0))
+%!assert (std (ones(1,2,1,1,0)), NaN (1,1,1,1,0))
+
+%!assert (std (ones (1,3,0,2)), NaN (1,1,0,2)) 
+%!assert (std (single (ones (1,3,0,2))), single (NaN (1,1,0,2)))
+
 ## Test input validation
 %!error std ()
 %!error std (1, 2, 3, 4)
@@ -127,5 +220,4 @@
 %!error <OPT must be 0 or 1> std (1, 2)
 %!error <DIM must be an integer> std (1, [], ones (2,2))
 %!error <DIM must be an integer> std (1, [], 1.5)
-%!error <DIM must be .* a valid dimension> std (1, [], 0)
-
+%!error <DIM must be .* a valid dimension> std (1, [], 0)
\ No newline at end of file
