histc

Computes histogram counts.

Syntax

n = histc(x, edges)

n = histc(x, edges, dim)

[n, idx] = histc(...)

Inputs

x
Data sample.
Type: double
Dimension: vector | matrix
edges
The histogram bin boundary values, in increasing order.
Type: double
Dimension: vector
dim
Dimension on which to assign histogram bins.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar

Outputs

n
The number of data points in each histogram bin along dimension dim. See comments.
Type: integer
Dimension: scalar | matrix
idx
The index of the histogram bin that contains each element of x. See comments.
Type: integer
Dimension: scalar | matrix

Examples

Bin counts for a beta distribution sample:
a = 5;
b = 2;
rand('seed', 2023);
x = betarnd(a,b,1,200);
n = histc(x, [0:0.1:1])
n = [Matrix] 1 x 11
0  1  1  6  7  24  39  45  61  16  0

Comments

For each vector along dimension dim, n(i) is the number of points in x contained in the half-open interval [edges(i), edges(i+1)), and n(end) is the number of points equal to edge(end).

For points in x that fall outside of the histogram bins, the idx value is set to zero.