Mercurial > hg > octave-lyh
comparison scripts/statistics/base/cut.m @ 3456:434790acb067
[project @ 2000-01-19 06:58:51 by jwe]
author | jwe |
---|---|
date | Wed, 19 Jan 2000 06:59:23 +0000 |
parents | 71d2e09c15a2 |
children | e031284eea27 |
comparison
equal
deleted
inserted
replaced
3455:f758be6e1730 | 3456:434790acb067 |
---|---|
27 ## which group each point in @var{x} belongs to. Groups are labelled | 27 ## which group each point in @var{x} belongs to. Groups are labelled |
28 ## from 1 to the number of groups; points outside the range of | 28 ## from 1 to the number of groups; points outside the range of |
29 ## @var{breaks} are labelled by @code{NaN}. | 29 ## @var{breaks} are labelled by @code{NaN}. |
30 ## @end deftypefn | 30 ## @end deftypefn |
31 | 31 |
32 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> | 32 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
33 ## Description: Cut data into intervals | 33 ## Description: Cut data into intervals |
34 | 34 |
35 function group = cut (X, BREAKS) | 35 function group = cut (X, BREAKS) |
36 | 36 |
37 if (nargin != 2) | 37 if (nargin != 2) |
38 usage ("cut (X, BREAKS)"); | 38 usage ("cut (X, BREAKS)"); |
39 endif | 39 endif |
40 | 40 |
41 if !is_vector (X) | 41 if !is_vector (X) |
42 error ("cut: X must be a vector"); | 42 error ("cut: X must be a vector"); |
43 endif | 43 endif |
44 if is_scalar (BREAKS) | 44 if is_scalar (BREAKS) |
45 BREAKS = linspace (min (X), max (X), BREAKS + 1); | 45 BREAKS = linspace (min (X), max (X), BREAKS + 1); |
46 BREAKS(1) = BREAKS(1) - 1; | 46 BREAKS(1) = BREAKS(1) - 1; |
47 elseif is_vector (BREAKS) | 47 elseif is_vector (BREAKS) |
48 BREAKS = sort (BREAKS); | 48 BREAKS = sort (BREAKS); |
49 else | 49 else |
50 error ("cut: BREAKS must be a scalar or vector"); | 50 error ("cut: BREAKS must be a scalar or vector"); |
51 endif | 51 endif |
52 | 52 |
53 group = NaN * ones (size (X)); | 53 group = NaN * ones (size (X)); |
54 m = length (BREAKS); | 54 m = length (BREAKS); |
55 if any (k = find ((X >= min (BREAKS)) & (X <= max (BREAKS)))) | 55 if any (k = find ((X >= min (BREAKS)) & (X <= max (BREAKS)))) |