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} {} create_set (@var{x}) |
|
21 ## Return a row vector containing the unique values in @var{x}, sorted in |
|
22 ## ascending order. For example, |
3426
|
23 ## |
3368
|
24 ## @example |
|
25 ## @group |
|
26 ## create_set ([ 1, 2; 3, 4; 4, 2 ]) |
|
27 ## @result{} [ 1, 2, 3, 4 ] |
|
28 ## @end group |
|
29 ## @end example |
5642
|
30 ## @seealso{union, intersection, complement} |
3408
|
31 ## @end deftypefn |
3368
|
32 |
2314
|
33 ## Author: jwe |
|
34 |
2311
|
35 function y = create_set(x) |
559
|
36 |
3457
|
37 if (nargin != 1) |
6046
|
38 print_usage (); |
559
|
39 endif |
|
40 |
3597
|
41 if (isempty(x)) |
559
|
42 y = []; |
|
43 else |
4862
|
44 nel = numel (x); |
|
45 y = sort (reshape (x, 1, nel)); |
|
46 els = find (y(1:nel-1) != y(2:nel)); |
3727
|
47 if (isempty (els)); |
|
48 y = y(1); |
|
49 else |
|
50 y = y([1, els+1]); |
|
51 endif |
559
|
52 endif |
2325
|
53 |
559
|
54 endfunction |