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