]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/values.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / values.m
1 ## Copyright (C) 1995-2012 Kurt Hornik
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 3 of the License, or (at
8 ## your option) 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, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} values (@var{x})
21 ## Return the different values in a column vector, arranged in ascending
22 ## order.
23 ##
24 ## As an example, @code{values([1, 2, 3, 1])} returns the vector
25 ## @code{[1, 2, 3]}.
26 ## @end deftypefn
27
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
29 ## Description: Extract unique elements
30
31 ## Deprecated in version 3.4
32
33 function v = values (x)
34
35   persistent warned = false;
36   if (! warned)
37     warned = true;
38     warning ("Octave:deprecated-function",
39              "values is obsolete and will be removed from a future version of Octave; please use unique instead");
40   endif
41
42   if (nargin != 1)
43     print_usage ();
44   endif
45
46   if (! (isvector (x)))
47     error ("values: X must be a vector");
48   endif
49
50   i = any (isnan (x));
51   ## HACK!
52   x = x(find(!isnan (x)));
53   n = length (x);
54   x = reshape (x, n, 1);
55   s = sort (x);
56   v = s([1; (find (s(2:n) > s(1:n-1)) + 1)]);
57   if (i)
58     v = [v; NaN];
59   endif
60
61 endfunction