diff scripts/set/setxor.m @ 19974:72ccbd36e23c

Return a column vector by default for Matlab compatibility (bug #44425, bug #44453). Document that only unique elements are returned from set functions. * NEWS: Announce change in default orientation of return values. * intersect.m, setdiff.m, setxor.m, union.m: Return a column vector by default unless the input is explicitly a row vector. Change docstring to note that only unique, non-duplicative elements are returned.
author Rik <rik@octave.org>
date Fri, 20 Mar 2015 18:23:01 -0700
parents 4197fc428c7d
children c3b2ec6a1586
line wrap: on
line diff
--- a/scripts/set/setxor.m	Thu Mar 19 14:32:40 2015 -0400
+++ b/scripts/set/setxor.m	Fri Mar 20 18:23:01 2015 -0700
@@ -23,11 +23,11 @@
 ## @deftypefnx {Function File} {@var{c} =} setxor (@var{a}, @var{b}, "rows")
 ## @deftypefnx {Function File} {[@var{c}, @var{ia}, @var{ib}] =} setxor (@dots{})
 ##
-## Return the elements exclusive to sets @var{a} or @var{b} sorted in
+## Return the unique elements exclusive to sets @var{a} or @var{b} sorted in
 ## ascending order.
 ##
-## If @var{a} and @var{b} are both column vectors return a column vector;
-## Otherwise, return a row vector.  The inputs may also be cell arrays of
+## If @var{a} and @var{b} are both row vectors then return a row vector;
+## Otherwise, return a column vector.  The inputs may also be cell arrays of
 ## strings.
 ##
 ## If the optional input @qcode{"rows"} is given then return the rows exclusive
@@ -50,7 +50,7 @@
   [a, b] = validsetargs ("setxor", a, b, varargin{:});
 
   by_rows = nargin == 3;
-  iscol = isvector (a) && isvector (b) && iscolumn (a) && iscolumn (b);
+  isrowvec = isvector (a) && isvector (b) && isrow (a) && isrow (b);
 
   ## Form A and B into sets.
   if (nargout > 1)
@@ -91,7 +91,7 @@
       endif
 
       ## Adjust output orientation for Matlab compatibility
-      if (! iscol)
+      if (isrowvec)
         c = c.';
       endif
     endif
@@ -112,8 +112,8 @@
 %! a = [3, 1, 4, 1, 5];
 %! b = [1, 2, 3, 4];
 %! [c, ia, ib] = setxor (a, b.');
-%! assert (c, [2, 5]);
-%! assert (c, sort ([a(ia), b(ib)]));
+%! assert (c, [2; 5]);
+%! assert (c, sort ([a(ia)'; b(ib)']));
 
 %!test
 %! a = [1 2; 4 5; 1 3];
@@ -156,8 +156,8 @@
 %! y = 2:5;
 
 %!assert (size (setxor (x, y)), [1 3])
-%!assert (size (setxor (x', y)), [1 3])
-%!assert (size (setxor (x, y')), [1 3])
+%!assert (size (setxor (x', y)), [3 1])
+%!assert (size (setxor (x, y')), [3 1])
 %!assert (size (setxor (x', y')), [3 1])
 
 ## Test multi-dimensional arrays
@@ -165,5 +165,5 @@
 %! a = rand (3,3,3);
 %! b = a;
 %! b(1,1,1) = 2;
-%! assert (intersect (a, b), sort (a(2:end)));
+%! assert (intersect (a, b), sort (a(2:end)'));