Mercurial > hg > octave-nkf
annotate scripts/set/complement.m @ 9665:1dba57e9d08d
use blas_trans_type for xgemm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 10:41:07 +0200 |
parents | eb63fbe60fab |
children |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007, |
2 ## 2008, 2009 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 | |
8898
ca032de5fbf2
Remove references to deprecated function create_set.
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8887
diff
changeset
|
31 ## @seealso{union, intersect, unique} |
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)) |
8887 | 43 y = unique (b); |
904 | 44 elseif (isempty (b)) |
559 | 45 y = []; |
46 else | |
8887 | 47 a = unique (a); |
48 b = unique (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 | |
7411 | 60 |
61 %!assert(all (all (complement ([1, 2, 3], [3; 4; 5; 6]) == [4, 5, 6]))); | |
62 | |
63 %!assert(all (all (complement ([1, 2, 3], [3, 4, 5, 6]) == [4, 5, 6]))); | |
64 | |
65 %!assert(isempty (complement ([1, 2, 3], [3, 2, 1]))); | |
66 | |
67 %!error complement (1); | |
68 | |
69 %!error complement (1, 2, 3); | |
70 |