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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
2303
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} create_set (@var{x}) |
|
22 ## Return a row vector containing the unique values in @var{x}, sorted in |
|
23 ## ascending order. For example, |
|
24 ## |
|
25 ## @example |
|
26 ## @group |
|
27 ## create_set ([ 1, 2; 3, 4; 4, 2 ]) |
|
28 ## @result{} [ 1, 2, 3, 4 ] |
|
29 ## @end group |
|
30 ## @end example |
3408
|
31 ## @end deftypefn |
3405
|
32 ## @seealso{union, intersection, and complement} |
3368
|
33 |
2314
|
34 ## Author: jwe |
|
35 |
2311
|
36 function y = create_set(x) |
559
|
37 |
|
38 if ( nargin != 1) |
904
|
39 usage ("create_set(x)"); |
559
|
40 endif |
|
41 |
|
42 if(isempty(x)) |
|
43 y = []; |
|
44 else |
|
45 [nrx, ncx] = size(x); |
|
46 nelx = nrx*ncx; |
|
47 x = reshape(x,1,nelx); |
|
48 y = zeros(1,nelx); |
|
49 |
|
50 x = sort(x); |
|
51 cur_val = y(1) = x(1); |
|
52 yindex = xindex = 2; |
|
53 |
|
54 while (xindex <= nelx) |
|
55 if(cur_val != x(xindex)) |
|
56 cur_val = x(xindex); |
|
57 y(yindex++) = cur_val; |
|
58 endif |
|
59 xindex++; |
|
60 endwhile |
|
61 y = y(1:(yindex-1)); |
|
62 endif |
2325
|
63 |
559
|
64 endfunction |