Mon 05 Apr 2010 05:11:51 PM UTC, original submission:
Hi all, I think there is a bug in cut() , or in its documentation. Reading the docs (second and third paras specifically -- see below), I would think it would return only 1 & 2 and the rest NaNs in the example, but it also returns 0. Why? Matlab?
If someone could clarify how the intervals to cut are supposed to be shaped, I would appreciate it. I would think like [ ) (closed on the minimum, open on the max), but I can't figure this out...
This behavior might be an attempt to deal with the interval situation, but if so it should be documented. Likewise for ML compatibility.
If in fact this is a bug, I promise to send a patch with (1) new docs (2) a bunch of tests added to cut(), and (perhaps) a fix.
I am running 3.2.4, but I get the same error the 3.3.50 on my freebsd box
Thoughts?
Supporting stuff -- first the cut help result, second some sample output, third
expected output:
## help cut
Function File: cut (X, BREAKS)
Create categorical data out of numerical or continuous data by cutting into intervals.
If BREAKS is a scalar, the data is cut into that many equal-width intervals. **If BREAKS is a vector of break points, the category has `length (BREAKS) - 1' groups.**
The returned value is a vector of the same size as X telling which group each point in X belongs to. **Groups are labelled from 1 to the number of groups**; points outside the range of BREAKS are labelled by `NaN'.
## output
data = -1:6
breaks = [0 2 4]
cdata = cut(data, breaks)
octave-3.2.4.exe:11> [data', cdata']
ans =
-1 NaN
0 0 # this shouldn't be here
1 1
2 1
3 2
4 2
5 NaN
6 NaN
## I would expect the following, assuming [,) behavior:
-1 NaN
- 1
1 1
2 2
3 2
4 NaN
5 NaN
6 NaN
|