7017
|
1 ## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2003, 2004, 2005, 2006, |
|
2 ## 2007 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} {} union (@var{x}, @var{y}) |
|
22 ## Return the set of elements that are in either of the sets @var{x} and |
|
23 ## @var{y}. For example, |
3426
|
24 ## |
3368
|
25 ## @example |
|
26 ## @group |
|
27 ## union ([ 1, 2, 4 ], [ 2, 3, 5 ]) |
|
28 ## @result{} [ 1, 2, 3, 4, 5 ] |
|
29 ## @end group |
|
30 ## @end example |
5642
|
31 ## @seealso{create_set, intersection, complement} |
3406
|
32 ## @end deftypefn |
3368
|
33 |
2314
|
34 ## Author: jwe |
|
35 |
2311
|
36 function y = union(a,b) |
559
|
37 |
|
38 if (nargin != 2) |
6046
|
39 print_usage (); |
559
|
40 endif |
|
41 |
4317
|
42 if (isempty (a)) |
|
43 y = create_set (b); |
|
44 elseif (isempty (b)) |
|
45 y = create_set (a); |
559
|
46 else |
4317
|
47 y = create_set ([a(:); b(:)]); |
|
48 if (size (a, 1) == 1 || size (b, 1) == 1) |
|
49 y = y(:).'; |
|
50 else |
|
51 y = y(:); |
|
52 endif |
559
|
53 endif |
|
54 |
|
55 endfunction |