Mercurial > octave-dspies
comparison scripts/set/setdiff.m @ 5967:d542d9197839 ss-2-9-8
[project @ 2006-08-24 21:24:53 by jwe]
author | jwe |
---|---|
date | Thu, 24 Aug 2006 21:27:41 +0000 |
parents | b3478d7a0486 |
children | 34f96dd5441b |
comparison
equal
deleted
inserted
replaced
5966:be252143f5e1 | 5967:d542d9197839 |
---|---|
54 ## Form a and b into combined set. | 54 ## Form a and b into combined set. |
55 b = unique (b, "rows"); | 55 b = unique (b, "rows"); |
56 [dummy, idx] = sortrows ([c; b]); | 56 [dummy, idx] = sortrows ([c; b]); |
57 ## Eliminate those elements of a that are the same as in b. | 57 ## Eliminate those elements of a that are the same as in b. |
58 n = length (dummy); | 58 n = length (dummy); |
59 c(idx(dummy(1:n-1) == dummy(2:n)), :) = []; | 59 c(idx(find (dummy(1:n-1) == dummy(2:n))), :) = []; |
60 endif | 60 endif |
61 else | 61 else |
62 c = unique (a); | 62 c = unique (a); |
63 if (! isempty (c) && ! isempty (b)) | 63 if (! isempty (c) && ! isempty (b)) |
64 ## Form a and b into combined set. | 64 ## Form a and b into combined set. |
65 b = unique (b); | 65 b = unique (b); |
66 [dummy, idx] = sort ([c(:); b(:)]); | 66 [dummy, idx] = sort ([c(:); b(:)]); |
67 ## Eliminate those elements of a that are the same as in b. | 67 ## Eliminate those elements of a that are the same as in b. |
68 n = length (dummy); | 68 n = length (dummy); |
69 c(idx(dummy(1:n-1) == dummy(2:n))) = []; | 69 c(idx(find (dummy(1:n-1) == dummy(2:n)))) = []; |
70 ## Reshape if necessary. | 70 ## Reshape if necessary. |
71 if (size (c, 1) != 1 && size (b, 1) == 1) | 71 if (size (c, 1) != 1 && size (b, 1) == 1) |
72 c = c.'; | 72 c = c.'; |
73 endif | 73 endif |
74 endif | 74 endif |