changeset 16675:558e1ce7247b

handle single output case of ndgrid * ndgrid.m: If one output is requested, return a column vector. New tests.
author Clemens Buchacher <drizzd@aon.at>
date Fri, 17 May 2013 13:56:52 -0400
parents bc79ac595a05
children f6dfc7705623
files scripts/plot/ndgrid.m
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/ndgrid.m	Fri May 17 12:56:44 2013 -0400
+++ b/scripts/plot/ndgrid.m	Fri May 17 13:56:52 2013 -0400
@@ -35,11 +35,11 @@
 function varargout = ndgrid (varargin)
 
   if (nargin == 1)
-    n = max ([nargout, 2]);
+    n = max ([nargout, 1]);
     ## If only one input argument is given, repeat it n-times
     varargin(1:n) = varargin(1);
-  elseif (nargin >= nargout)
-    n = max ([nargin, 2]);
+  elseif (nargin > 0 && nargin >= nargout)
+    n = max ([nargin, 1]);
   else
     error ("ndgrid: wrong number of input arguments");
   endif
@@ -72,6 +72,17 @@
 
 
 %!test
+%! x = 1:3;
+%! assert (isequal (ndgrid (x), x(:)));
+
+%!test
+%! x = 1:3;
+%! [XX, YY] = ndgrid (x);
+%! assert (size_equal (XX, YY));
+%! assert (isequal (XX, repmat(x(:), 1, numel(x))));
+%! assert (isequal (YY, repmat(x, numel(x), 1)));
+
+%!test
 %! x = 1:2;
 %! y = 1:3;
 %! z = 1:4;