Mercurial > hg > octave-nkf
changeset 16778:e205f5ea826a
ndgrid.m: Fix Matlab incompatibility with null inputs (bug #38685).
* scripts/plot/ndgrid.m: Change input validation to accept [] inputs.
Add %! tests for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 19 Jun 2013 16:51:30 -0700 |
parents | 59b08464d971 |
children | 8fce0ed4894a |
files | scripts/plot/ndgrid.m |
diffstat | 1 files changed, 13 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/ndgrid.m +++ b/scripts/plot/ndgrid.m @@ -34,11 +34,13 @@ function varargout = ndgrid (varargin) - if (nargin == 1) + if (nargin == 0) + print_usage (); + elseif (nargin == 1) n = max ([nargout, 1]); ## If only one input argument is given, repeat it n-times varargin(1:n) = varargin(1); - elseif (nargin > 0 && nargin >= nargout) + elseif (nargin >= nargout) n = max ([nargin, 1]); else error ("ndgrid: wrong number of input arguments"); @@ -47,12 +49,10 @@ ## Determine the size of the output arguments shape = zeros (1, n); - for i = 1:n - if (! isvector (varargin{i})) + if (! isvector (varargin{i}) && ! isempty (varargin{i})) error ("ndgrid: arguments must be vectors"); endif - shape(i) = length (varargin{i}); endfor @@ -108,3 +108,11 @@ %! assert (XX1, XX2.'); %! assert (YY1, YY2.'); +%!assert (ndgrid ([]), zeros(0,1)) +%!assert (ndgrid ([], []), zeros(0,0)) + +%% Test input validation +%!error ndgrid () +%!error <wrong number of input arguments> [a,b,c] = ndgrid (1:3,1:3) +%!error <arguments must be vectors> ndgrid (ones (2,2)) +