Mercurial > hg > octave-lyh
comparison scripts/set/complement.m @ 904:3470f1e25a79
[project @ 1994-11-09 21:22:15 by jwe]
author | jwe |
---|---|
date | Wed, 09 Nov 1994 21:22:15 +0000 |
parents | 4e826edfbc56 |
children | 5cffc4b8de57 |
comparison
equal
deleted
inserted
replaced
903:b3692d63cca3 | 904:3470f1e25a79 |
---|---|
1 function y = complement(a,b) | 1 function y = complement (a, b) |
2 | 2 |
3 # usage: complement(a,b) | 3 # usage: complement (a, b) |
4 # | 4 # |
5 # Returns the elements of set b that are not in set a. | 5 # Returns the elements of set b that are not in set a. |
6 # | 6 # |
7 # See - create_set, union, intersection | 7 # See - create_set, union, intersection |
8 | 8 |
9 if(nargin != 2) | 9 if (nargin != 2) |
10 error("usage: complement(a,b)"); | 10 usage ("complement(a,b)"); |
11 endif | 11 endif |
12 | 12 |
13 if(isempty(a)) | 13 if (isempty (a)) |
14 y = create_set(b); | 14 y = create_set(b); |
15 elseif(isempty(b)) | 15 elseif (isempty (b)) |
16 y = []; | 16 y = []; |
17 else | 17 else |
18 a = create_set(a); | 18 a = create_set (a); |
19 b = create_set(b); | 19 b = create_set (b); |
20 yindex = 1; | 20 yindex = 1; |
21 y = zeros(1,length(b)); | 21 y = zeros (1, length (b)); |
22 for index = 1:length(b) | 22 for index = 1:length (b) |
23 if(all(a != b(index))) | 23 if (all (a != b (index))) |
24 y(yindex++) = b(index); | 24 y(yindex++) = b(index); |
25 endif | 25 endif |
26 endfor | 26 endfor |
27 y = y(1:(yindex-1)); | 27 y = y(1:(yindex-1)); |
28 endif | 28 endif |