559
|
1 function y = complement(a,b) |
|
2 |
|
3 # usage: complement(a,b) |
|
4 # |
|
5 # Returns the elements of set b that are not in set a. |
|
6 # |
|
7 # See - create_set, union, intersection |
|
8 |
|
9 if(nargin != 2) |
|
10 error("usage: complement(a,b)"); |
|
11 endif |
|
12 |
|
13 if(isempty(a)) |
|
14 y = create_set(b); |
|
15 elseif(isempty(b)) |
|
16 y = []; |
|
17 else |
|
18 a = create_set(a); |
|
19 b = create_set(b); |
|
20 yindex = 1; |
|
21 y = zeros(1,length(b)); |
|
22 for index = 1:length(b) |
|
23 if(all(a != b(index))) |
|
24 y(yindex++) = b(index); |
|
25 endif |
|
26 endfor |
|
27 y = y(1:(yindex-1)); |
|
28 endif |
|
29 |
|
30 endfunction |
|
31 |