mode

Most frequent value in a sample.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

M = mode(A)

Most frequent value of a vector, or of each column of a matrix.

M = mode(A, dim)

Along dimension dim.

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

Also returns the occurrence count F and the tied values C (MATLAB only; see notes).

Description

When several values tie for the highest count, mode returns the smallest of them. The statistic is mostly meaningful for discrete data, since in continuous data it is rare for a value to repeat.

Empty input gives NaN.

Input arguments

A
Numeric or logical array.
dim
Dimension to operate along.

Output arguments

M
The most frequent value.
F
Number of occurrences of M.
C
Cell array holding every value that ties for most frequent.

Example

Ties go to the smallest

mode([1 2 2 3 3])
mode([4 4 4 1 2])
mode([1 2; 1 3; 2 3])
Output
ans = 2
ans = 4
ans = 1×2

     1     3

See also

mean median histcounts unique