Mercurial > hg > octave-jordi
changeset 18842:30d8501a857a
setdiff.m: Orient output (row/column) the same as Matlab (bug #42577).
* setdiff.m: Only output a column vector if both inputs are column vectors or
the second argument is a scalar.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 18 Jun 2014 13:03:27 -0700 |
parents | 5eca3080c7cd |
children | 3d33fe79816c |
files | scripts/set/setdiff.m |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/setdiff.m +++ b/scripts/set/setdiff.m @@ -81,8 +81,8 @@ if (nargout > 1) i(idx(dups)) = []; endif - ## Reshape if necessary. - if (rows (c) != 1 && rows (b) == 1) + ## Reshape if necessary for Matlab compatibility. + if (iscolumn (c) && ! iscolumn (b)) c = c.'; endif endif @@ -105,3 +105,16 @@ %! assert (y, [5]); %! assert (y, a(i)); +%% Test output orientation compatibility (bug #42577) +%!assert (setdiff ([1:5], 2), [1,3,4,5]) +%!assert (setdiff ([1:5]', 2), [1;3;4;5]) +%!assert (setdiff ([1:5], [2:3]), [1,4,5]) +%!assert (setdiff ([1:5], [2:3]'), [1,4,5]) +%!assert (setdiff ([1:5]', [2:3]), [1,4,5]) +%!assert (setdiff ([1:5]', [2:3]'), [1;4;5]) + +%% Test input validation +%!error setdiff () +%!error setdiff (1) +%!error setdiff (1,2,3,4) +