Mercurial > hg > octave-lyh
annotate scripts/set/create_set.m @ 8286:6f2d95255911
fix @seealso references to point to existing anchors
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Wed, 29 Oct 2008 17:52:54 -0400 |
parents | 83a8781b529d |
children |
rev | line source |
---|---|
7344 | 1 ## Copyright (C) 1994, 1996, 1997, 1999, 2000, 2004, 2005, 2006, 2007, 2008 |
7017 | 2 ## 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} {} create_set (@var{x}) | |
7344 | 22 ## @deftypefnx{Function File} {} create_set (@var{x}, "rows") |
3368 | 23 ## Return a row vector containing the unique values in @var{x}, sorted in |
24 ## ascending order. For example, | |
3426 | 25 ## |
3368 | 26 ## @example |
27 ## @group | |
7344 | 28 ## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ]) |
3368 | 29 ## @result{} [ 1, 2, 3, 4 ] |
30 ## @end group | |
31 ## @end example | |
7344 | 32 ## |
33 ## If the optional second input argument is the string "rows" each row of | |
34 ## the matrix @var{x} will be considered an element of set. For example, | |
35 ## @example | |
36 ## @group | |
37 ## create_set ([ 1, 2; 3, 4; 4, 2; 1, 2 ], "rows") | |
38 ## @result{} 1 2 | |
39 ## 3 4 | |
40 ## 4 2 | |
41 ## @end group | |
42 ## @end example | |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
43 ## @seealso{union, intersect, complement, unique} |
3408 | 44 ## @end deftypefn |
3368 | 45 |
2314 | 46 ## Author: jwe |
47 | |
7344 | 48 function y = create_set (x, rows_opt) |
559 | 49 |
7344 | 50 if (nargin < 1 || nargin > 2) |
6046 | 51 print_usage (); |
559 | 52 endif |
7344 | 53 |
54 if (nargin == 1) | |
55 y = unique (x).'; | |
56 elseif (strcmpi (rows_opt, "rows")) | |
57 y = unique (x, "rows"); | |
559 | 58 else |
7344 | 59 error ("create_set: expecting \"rows\" as second argument"); |
559 | 60 endif |
2325 | 61 |
559 | 62 endfunction |
7411 | 63 |
64 %!assert(all (all (create_set ([1, 2; 3, 4; 2, 4]) == [1, 2, 3, 4]))); | |
65 | |
66 %!assert(all (all (create_set ([1; 2; 3; 4; 2; 4]) == [1, 2, 3, 4]))); | |
67 | |
68 %!assert(isempty (create_set ([]))); | |
69 | |
70 %!error create_set (1, 2); | |
71 |