MATLAB Function Reference  histc

Histogram count

Syntax

• ```n = histc(x,edges)
n = histc(x,edges,dim)
[n,bin] = histc(...)
```

Description

```n = histc(x,edges) ``` counts the number of values in vector `x` that fall between the elements in the `edges` vector (which must contain monotonically nondecreasing values). `n` is a `length``(edges)` vector containing these counts.

`n(k)` counts the value `x(i)` if `edges(k) <= x(i) < edges(k+1)`. The last bin counts any values of `x` that match `edges(end)`. Values outside the values in `edges` are not counted. Use `-inf` and `inf` in `edges` to include all non-`NaN` values.

For matrices, `histc(x,edges)` returns a matrix of column histogram counts. For N-D arrays, `histc(x,edges)` operates along the first nonsingleton dimension.

```n = histc(x,edges,dim) ``` operates along the dimension `dim`.

```[n,bin] = histc(...) ``` also returns an index matrix `bin`. If `x` is a vector, `n(k)` `= sum(bin==k)`. `bin` is zero for out of range values. If `x` is an `M`-by-`N` matrix, then

• ```for j=1:N, n(k,j) = sum(bin(:,j)==k); end
```

To plot the histogram, use the `bar` command.

See Also

`hist`

Specialized Plotting for related functions

© 1994-2005 The MathWorks, Inc.