# HG changeset patch # User Clemens Buchacher # Date 1368813412 14400 # Node ID 558e1ce7247bece11ecdf9fe0c97dd7280350682 # Parent bc79ac595a05252500f7ddde73f349414a3af05f handle single output case of ndgrid * ndgrid.m: If one output is requested, return a column vector. New tests. diff -r bc79ac595a05 -r 558e1ce7247b scripts/plot/ndgrid.m --- 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;