Mercurial > hg > octave-nkf
changeset 17902:9bcf1614cd80
ndgrid.m: Don't call reshape with a single dimension input.
* ndgrid.m: Make special case for single input vector which is not
gridded up, but simply returned as a column vector.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 11 Nov 2013 17:47:00 -0800 |
parents | 2c241092b47b |
children | de8591a19bc6 |
files | scripts/plot/util/ndgrid.m |
diffstat | 1 files changed, 20 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/ndgrid.m +++ b/scripts/plot/util/ndgrid.m @@ -43,36 +43,40 @@ 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); + nd = max (nargout, 1); + ## If only one input argument is given, repeat it nd-times + varargin(1:nd) = varargin(1); elseif (nargin >= nargout) - n = max ([nargin, 1]); + nd = max (nargin, 1); else error ("ndgrid: wrong number of input arguments"); endif ## Determine the size of the output arguments - - shape = zeros (1, n); - for i = 1:n + shape = zeros (1, nd); + for i = 1:nd if (! isvector (varargin{i}) && ! isempty (varargin{i})) error ("ndgrid: arguments must be vectors"); endif shape(i) = length (varargin{i}); endfor - for i = 1:n - ## size for reshape - r = ones (1, n); - r(i) = shape(i); + if (nd == 1) + ## Special case, single input vector + varargout{1} = varargin{1}(:); + else + for i = 1:nd + ## size for reshape + r = ones (1, nd+1); + r(i) = shape(i); - ## size for repmat - s = shape; - s(i) = 1; + ## size for repmat + s = shape; + s(i) = 1; - varargout{i} = repmat (reshape (varargin{i}, r), s); - endfor + varargout{i} = repmat (reshape (varargin{i}, r), s); + endfor + endif endfunction