Note: This page has been translated by MathWorks. Please click here

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

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

Most frequent values in array

`M = mode(A)`

`M = mode(A,dim)`

```
[M,F] =
mode(___)
```

```
[M,F,C]
= mode(___)
```

returns
the sample mode of `M`

= mode(`A`

)`A`

, which is the most frequently
occurring value in `A`

. When there are multiple values
occurring equally frequently, `mode`

returns the
smallest of those values. For complex inputs, the smallest value is
the first value in a sorted list.

If

`A`

is a vector, then`mode(A)`

returns the most frequent value of`A`

.If

`A`

is a nonempty matrix, then`mode(A)`

returns a row vector containing the mode of each column of`A`

.If

`A`

is an empty 0-by-0 matrix,`mode(A)`

returns`NaN`

.If

`A`

is a multidimensional array, then`mode(A)`

treats the values along the first array dimension whose size does not equal`1`

as vectors and returns an array of most frequent values. The size of this dimension becomes`1`

while the sizes of all other dimensions remain the same.

The

`mode`

function is most useful with discrete or coarsely rounded data. The mode for a continuous probability distribution is defined as the peak of its density function. Applying the`mode`

function to a sample from that distribution is unlikely to provide a good estimate of the peak; it would be better to compute a histogram or density estimate and calculate the peak of that estimate. Also, the`mode`

function is not suitable for finding peaks in distributions having multiple modes.

`histcounts`

| `histogram`

| `mean`

| `median`

| `sort`

Was this topic helpful?