Skip to content

discretize

Bin numeric values into discrete categories.

Y = discretize(X, edges)
Y = discretize(X, N)
[Y, E] = discretize(X, ...)

Sorts the values of X into bins. With edges (a vector of bin edges), each X(i) is assigned an integer index — the bin it falls into. With N (an integer count), the range is split into N equal-width bins. Optional second output E returns the bin edges actually used.

discretize([0.1 0.5 0.9], [0 0.3 0.7 1]) % [1 2 3]
discretize([1 2 3 4 5], 2) % [1 1 2 2 2]