Mercurial > hg > octave-nkf
changeset 14148:402acc45350e stable
intersect.m: Properly handle the "rows" case with more than 1 output arg (bug #35247)
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 05 Jan 2012 10:27:34 -0500 |
parents | 71e28fda7be9 |
children | f1ff06a1d73a |
files | scripts/set/intersect.m |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/intersect.m +++ b/scripts/set/intersect.m @@ -57,6 +57,7 @@ [c, ic] = sortrows (c); ii = find (all (c(1:end-1,:) == c(2:end,:), 2)); c = c(ii,:); + len_a = rows (a); else c = [a(:); b(:)]; [c, ic] = sort (c); ## [a(:);b(:)](ic) == c @@ -66,11 +67,12 @@ ii = find (c(1:end-1) == c(2:end)); endif c = c(ii); + len_a = length (a); endif if (nargout > 1) ia = ja(ic(ii)); ## a(ia) == c - ib = jb(ic(ii+1) - length (a)); ## b(ib) == c + ib = jb(ic(ii+1) - len_a); ## b(ib) == c endif if (nargin == 2 && (size (b, 1) == 1 || size (a, 1) == 1)) @@ -105,3 +107,9 @@ %! b = [1 2 3 4 5 6]; %! c = intersect(a,b); %! assert(c, [1,2]); +%!test +%! a = [1 2 3 4; 5 6 7 8; 9 10 11 12]; +%! [b, ia, ib] = intersect(a, a, "rows"); +%! assert(b, a); +%! assert(ia, [1:3]'); +%! assert(ib, [1:3]');