# HG changeset patch # User Rik # Date 1403121807 25200 # Node ID 30d8501a857a5bf7d693e1c0f4347a358e86fd29 # Parent 5eca3080c7cdca8851c217bb0e369be1459389d8 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. diff -r 5eca3080c7cd -r 30d8501a857a scripts/set/setdiff.m --- a/scripts/set/setdiff.m Sat Jun 14 13:24:46 2014 -0700 +++ b/scripts/set/setdiff.m Wed Jun 18 13:03:27 2014 -0700 @@ -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) +