Syntax

Description

bincounts = histc(x,binranges) counts
the number of values in x that are within each
specified bin range. The input, binranges, determines
the endpoints for each bin. The output, bincounts,
contains the number of elements from x in each
bin.

If x is a vector, then histc returns bincounts as
a vector of histogram bin counts.

If x is a matrix, then histc operates
along each column of x and returns bincounts as
a matrix of histogram bin counts for each column.

Examples

Initialize the random number generator to make the output of randn repeatable.

rng(0,'twister')

Define x as 100 normally distributed random numbers. Define bin ranges between -4 and 4. Determine the number of values in x that are within each specified bin range. Return the number of elements in each bin in bincounts.

Input Arguments

Values to be sorted, specified as a vector or a matrix. The
bin counts do not include values in x that are NaN or
that lie outside the specified bin ranges. If x contains
complex values, then histc ignores the imaginary
parts and uses only the real parts.

Bin ranges, specified as a vector of monotonically nondecreasing
values or a matrix of monotonically nondecreasing values running down
each successive column. The values in binranges determine
the left and right endpoints for each bin. If binranges contains
complex values, then histc ignores the imaginary
parts and uses only the real parts.

If binranges is a matrix, then histc determines
the bin ranges by using values running down successive columns. Each
bin includes the left endpoint, but does not include the right endpoint.
The last bin consists of the scalar value equal to last value in binranges.

For example, if binranges equals the vector [0,5,10,13],
then histc creates four bins. The first bin includes
values greater than or equal to 0 and strictly less than 5. The second
bin includes values greater than or equal to 5 and less than 10, and
so on. The last bin contains the scalar value 13.

More About

If values in x lie outside the
specified bin ranges, then histc does not include
these values in the bin counts. Start and end the binranges vector
with -inf and inf to ensure
that all values in x are included in the bin counts.