Mercurial > hg > octave-nkf
changeset 18081:42df174ec2ff stable
setxor.m: Fix bug when "rows" argument given (bug #40808).
* setxor.m: When "rows" argument given, use ':' to pick up all columns in find.
Add %!test to check behavior.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 04 Dec 2013 14:51:45 -0800 |
parents | d8d0e9e189f5 |
children | c3e7da9836bd |
files | scripts/set/setxor.m |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/setxor.m +++ b/scripts/set/setxor.m @@ -61,7 +61,7 @@ na = rows (a); nb = rows (b); [c, i] = sortrows ([a; b]); n = rows (c); - idx = find (all (c(1:n-1) == c(2:n), 2)); + idx = find (all (c(1:n-1, :) == c(2:n, :), 2)); if (! isempty (idx)) c([idx, idx+1],:) = []; i([idx, idx+1],:) = []; @@ -94,9 +94,16 @@ %!assert (setxor ([1,2,3],[2,3,4]),[1,4]) %!assert (setxor ({'a'}, {'a', 'b'}), {'b'}) + %!test %! a = [3, 1, 4, 1, 5]; b = [1, 2, 3, 4]; -%! [y, ia, ib] = setxor (a, b.'); -%! assert (y, [2, 5]); -%! assert (y, sort ([a(ia), b(ib)])); +%! [c, ia, ib] = setxor (a, b.'); +%! assert (c, [2, 5]); +%! assert (c, sort ([a(ia), b(ib)])); +%!test +%! a = [1 2; 4 5; 1 3]; b = [1 1; 1 2; 4 5; 2 10]; +%! [c, ia, ib] = setxor (a, b, "rows"); +%! assert (c, [1 1; 1 3; 2 10]); +%! assert (c, sortrows ([a(ia,:); b(ib,:)])); +