mode
Most frequent values in array
Syntax
Description
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, thenmode(A)
returns the most frequent value ofA
.If
A
is a nonempty matrix, thenmode(A)
returns a row vector containing the mode of each column ofA
.If
A
is an empty 0-by-0 matrix,mode(A)
returnsNaN
.If
A
is a multidimensional array, thenmode(A)
treats the values along the first array dimension whose size does not equal1
as vectors and returns an array of most frequent values. The size of this dimension becomes1
while the sizes of all other dimensions remain the same.If
A
is a table or timetable, thenmode(A)
returns a one-row table containing the mode of each variable. (since R2023a)
Examples
Input Arguments
Output Arguments
Tips
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 themode
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, themode
function is not suitable for finding peaks in distributions having multiple modes.
Extended Capabilities
Version History
Introduced before R2006aSee Also
mean
| median
| histogram
| histcounts
| sort