Mercurial > hg > octave-nkf
comparison scripts/set/intersect.m @ 5821:11e4ae44984f
[project @ 2006-05-17 21:05:53 by jwe]
author | jwe |
---|---|
date | Wed, 17 May 2006 21:05:53 +0000 |
parents | 27c966e4b2dc |
children | 34f96dd5441b |
comparison
equal
deleted
inserted
replaced
5820:27c966e4b2dc | 5821:11e4ae44984f |
---|---|
41 else | 41 else |
42 ## form a and b into sets | 42 ## form a and b into sets |
43 [a, ja] = unique (a); | 43 [a, ja] = unique (a); |
44 [b, jb] = unique (b); | 44 [b, jb] = unique (b); |
45 | 45 |
46 c = [ a(:); b(:) ]; | 46 c = [a(:); b(:)]; |
47 [c, ic] = sort( c ); ## [a(:);b(:)](ic) == c | 47 [c, ic] = sort (c); ## [a(:);b(:)](ic) == c |
48 | 48 |
49 ii = find( c(1:end-1) == c(2:end) ); | 49 ii = find( c(1:end-1) == c(2:end) ); |
50 | 50 |
51 c = c(ii); ## The answer | 51 c = c(ii); ## The answer |
52 ia = ja(ic(ii)); ## a(ia) == c | 52 ia = ja(ic(ii)); ## a(ia) == c |
53 ib = jb(ic(ii+1) - length(a)); ## b(ib) == c | 53 ib = jb(ic(ii+1) - length (a)); ## b(ib) == c |
54 | 54 |
55 | 55 |
56 if ( size (b, 1) == 1 || size (a, 1) == 1 ) | 56 if (size (b, 1) == 1 || size (a, 1) == 1) |
57 c = c.'; | 57 c = c.'; |
58 endif | 58 endif |
59 endif | 59 endif |
60 | 60 |
61 endfunction | 61 endfunction |