mode
Most frequent values in array
Syntax
M =mode(A)
M =mode(A,dim)
[M,F] = mode(___)
[M,F,C] = mode(___)
Description
returns the sample mode ofM
= mode(A
)A
, which is the most frequently occurring value inA
. 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
是a vector, thenmode(A)
returns the most frequent value ofA
.If
A
是a nonempty matrix, thenmode(A)
returns a row vector containing the mode of each column ofA
.If
A
是an empty 0-by-0 matrix,mode(A)
returnsNaN
.If
A
是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.
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.