Mercurial > hg > octave-nkf
annotate scripts/deprecated/cut.m @ 14518:67e865f5272c
Added tag release-3-6-1 for changeset ba4d6343524b
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 03 Apr 2012 22:37:50 -0400 |
parents | 72c96de7a403 |
children | 86854d032a37 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12797
diff
changeset
|
1 ## Copyright (C) 1996-2012 Kurt Hornik |
3426 | 2 ## |
3922 | 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. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3200 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3200 | 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/>. | |
3200 | 18 |
3453 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} cut (@var{x}, @var{breaks}) | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
21 ## Create categorical data from numerical or continuous data by |
3200 | 22 ## cutting into intervals. |
23 ## | |
3453 | 24 ## If @var{breaks} is a scalar, the data is cut into that many |
25 ## equal-width intervals. If @var{breaks} is a vector of break points, | |
26 ## the category has @code{length (@var{breaks}) - 1} groups. | |
3200 | 27 ## |
3453 | 28 ## The returned value is a vector of the same size as @var{x} telling |
29 ## which group each point in @var{x} belongs to. Groups are labelled | |
30 ## from 1 to the number of groups; points outside the range of | |
31 ## @var{breaks} are labelled by @code{NaN}. | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
32 ## @seealso{histc} |
3453 | 33 ## @end deftypefn |
3200 | 34 |
5428 | 35 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 36 ## Description: Cut data into intervals |
3200 | 37 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
38 function group = cut (x, breaks) |
3426 | 39 |
12797
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 persistent warned = false; |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 if (! warned) |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 warned = true; |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 warning ("Octave:deprecated-function", |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
44 "cut is obsolete and will be removed from a future version of Octave; please use histc instead"); |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 endif |
71265f725b11
codesprint: Deprecate cut() function.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 |
3200 | 47 if (nargin != 2) |
6046 | 48 print_usage (); |
3200 | 49 endif |
50 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
51 if (!isvector (x)) |
3456 | 52 error ("cut: X must be a vector"); |
3200 | 53 endif |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
54 if isscalar (breaks) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
55 breaks = linspace (min (x), max (x), breaks + 1); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
56 breaks(1) = breaks(1) - 1; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
57 elseif isvector (breaks) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
58 breaks = sort (breaks); |
3200 | 59 else |
3456 | 60 error ("cut: BREAKS must be a scalar or vector"); |
3200 | 61 endif |
62 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
63 group = NaN (size (x)); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
64 m = length (breaks); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
65 if any (k = find ((x >= min (breaks)) & (x < max (breaks)))) |
3200 | 66 n = length (k); |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
67 group(k) = sum ((ones (m, 1) * reshape (x(k), 1, n)) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10488
diff
changeset
|
68 >= (reshape (breaks, m, 1) * ones (1, n))); |
3200 | 69 endif |
70 | |
71 endfunction |