559
|
1 function y = create_set(x) |
|
2 |
|
3 # usage: create_set(x) |
|
4 # |
|
5 # Returns the unique elements of x, sorted in ascending order. |
|
6 # |
|
7 # See - union, intersection, complement |
|
8 |
|
9 if ( nargin != 1) |
|
10 error("usage: create_set(x)"); |
|
11 endif |
|
12 |
|
13 if(isempty(x)) |
|
14 y = []; |
|
15 else |
|
16 [nrx, ncx] = size(x); |
|
17 nelx = nrx*ncx; |
|
18 x = reshape(x,1,nelx); |
|
19 y = zeros(1,nelx); |
|
20 |
|
21 x = sort(x); |
|
22 cur_val = y(1) = x(1); |
|
23 yindex = xindex = 2; |
|
24 |
|
25 while (xindex <= nelx) |
|
26 if(cur_val != x(xindex)) |
|
27 cur_val = x(xindex); |
|
28 y(yindex++) = cur_val; |
|
29 endif |
|
30 xindex++; |
|
31 endwhile |
|
32 y = y(1:(yindex-1)); |
|
33 endif |
|
34 |
|
35 endfunction |
|
36 |