Mercurial > hg > octave-nkf
annotate scripts/deprecated/cut.m @ 14552:86854d032a37
maint: miscellaneous style fixes for .m files
* audio/mu2lin.m, deprecated/cut.m, general/cplxpair.m,
general/genvarname.m, geometry/rectint.m, help/gen_doc_cache.m,
image/hsv2rgb.m, image/rainbow.m, io/textscan.m,
miscellaneous/bzip2.m, miscellaneous/compare_versions.m,
miscellaneous/fact.m, miscellaneous/menu.m, optimization/fminbnd.m,
optimization/fminunc.m, optimization/fzero.m, optimization/sqp.m,
plot/__gnuplot_drawnow__.m, plot/axis.m, plot/findobj.m,
plot/legend.m, plot/peaks.m, plot/private/__errplot__.m,
plot/private/__fltk_print__.m, plot/private/__go_draw_axes__.m,
plot/private/__patch__.m, polynomial/pchip.m, polynomial/residue.m,
signal/periodogram.m, sparse/sprandsym.m, statistics/base/moment.m,
statistics/distributions/expcdf.m, statistics/distributions/expinv.m,
statistics/distributions/exppdf.m, statistics/tests/prop_test_2.m,
statistics/tests/sign_test.m, statistics/tests/t_test.m,
statistics/tests/t_test_2.m, statistics/tests/t_test_regression.m,
strings/regexptranslate.m, time/datetick.m:
Style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Apr 2012 22:07:00 -0400 |
parents | 72c96de7a403 |
children | 1c89599167a6 |
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 |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
54 if (isscalar (breaks)) |
11436
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; |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
57 elseif (isvector (breaks)) |
11436
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); |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14138
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 |