7017
|
1 ## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007 |
|
2 ## John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
2303
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} complement (@var{x}, @var{y}) |
|
22 ## Return the elements of set @var{y} that are not in set @var{x}. For |
|
23 ## example, |
3426
|
24 ## |
3368
|
25 ## @example |
|
26 ## @group |
|
27 ## complement ([ 1, 2, 3 ], [ 2, 3, 5 ]) |
|
28 ## @result{} 5 |
|
29 ## @end group |
|
30 ## @end example |
5642
|
31 ## @seealso{create_set, union, intersection} |
3408
|
32 ## @end deftypefn |
3368
|
33 |
2314
|
34 ## Author: jwe |
|
35 |
2311
|
36 function y = complement (a, b) |
559
|
37 |
904
|
38 if (nargin != 2) |
6046
|
39 print_usage (); |
559
|
40 endif |
|
41 |
904
|
42 if (isempty (a)) |
559
|
43 y = create_set(b); |
904
|
44 elseif (isempty (b)) |
559
|
45 y = []; |
|
46 else |
904
|
47 a = create_set (a); |
|
48 b = create_set (b); |
559
|
49 yindex = 1; |
904
|
50 y = zeros (1, length (b)); |
|
51 for index = 1:length (b) |
|
52 if (all (a != b (index))) |
559
|
53 y(yindex++) = b(index); |
|
54 endif |
|
55 endfor |
|
56 y = y(1:(yindex-1)); |
|
57 endif |
|
58 |
|
59 endfunction |