Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Bivariate histogram bin counts

```
[N,Xedges,Yedges]
= histcounts2(X,Y)
```

```
[N,Xedges,Yedges]
= histcounts2(X,Y,nbins)
```

```
[N,Xedges,Yedges]
= histcounts2(X,Y,Xedges,Yedges)
```

```
[N,Xedges,Yedges]
= histcounts2(___,Name,Value)
```

```
[N,Xedges,Yedges,binX,binY]
= histcounts2(___)
```

`[`

partitions the
values in `N`

,`Xedges`

,`Yedges`

]
= histcounts2(`X,Y`

)`X`

and `Y`

into 2-D bins,
and returns the bin counts, as well as the bin edges in each dimension.
The `histcounts2`

function uses an automatic binning
algorithm that returns uniform bins chosen to cover the range of values
in `X`

and `Y`

and reveal the underlying
shape of the distribution.

`[`

partitions `N`

,`Xedges`

,`Yedges`

]
= histcounts2(`X,Y`

,`Xedges`

,`Yedges`

)`X`

and `Y`

into
bins with the bin edges specified by `Xedges`

and `Yedges`

.

`N(i,j)`

counts the value `[X(k),Y(k)]`

if `Xedges(i)`

≤ `X(k)`

< `Xedges(i+1)`

and `Yedges(j)`

≤ `Y(k)`

< `Yedges(j+1)`

.
The last bins in each dimension also include the last (outer) edge.
For example, `[X(k),Y(k)]`

falls into the `i`

th
bin in the last row if `Xedges(end-1)`

≤ `X(k)`

≤ `Xedges(end)`

and `Yedges(i)`

≤ `Y(k)`

< `Yedges(i+1)`

.

`[`

uses
additional options specified by one or more `N`

,`Xedges`

,`Yedges`

]
= histcounts2(___,`Name,Value`

)`Name,Value`

pair
arguments using any of the input arguments in previous syntaxes. For
example, you can specify `'BinWidth'`

and a two-element
vector to adjust the width of the bins in each dimension.

`[`

also returns index arrays `N`

,`Xedges`

,`Yedges`

,`binX`

,`binY`

]
= histcounts2(___)`binX`

and `binY`

,
using any of the previous syntaxes. `binX`

and `binY`

are
arrays of the same size as `X`

and `Y`

whose
elements are the bin indices for the corresponding elements in `X`

and `Y`

.
The number of elements in the `(i,j)`

th bin is equal
to `nnz(binX==i & binY==j)`

, which is the same
as `N(i,j)`

if `Normalization`

is `'count'`

.

`discretize`

| `fewerbins`

| `histcounts`

| `histogram`

| `histogram2`

| `morebins`

Was this topic helpful?