Mercurial > hg > octave-avbm
diff scripts/set/complement.m @ 559:4e826edfbc56
[project @ 1994-07-25 22:18:28 by jwe]
Initial revision
author | jwe |
---|---|
date | Mon, 25 Jul 1994 22:19:05 +0000 |
parents | |
children | 3470f1e25a79 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/scripts/set/complement.m @@ -0,0 +1,31 @@ +function y = complement(a,b) + +# usage: complement(a,b) +# +# Returns the elements of set b that are not in set a. +# +# See - create_set, union, intersection + + if(nargin != 2) + error("usage: complement(a,b)"); + endif + + if(isempty(a)) + y = create_set(b); + elseif(isempty(b)) + y = []; + else + a = create_set(a); + b = create_set(b); + yindex = 1; + y = zeros(1,length(b)); + for index = 1:length(b) + if(all(a != b(index))) + y(yindex++) = b(index); + endif + endfor + y = y(1:(yindex-1)); + endif + +endfunction +