categorical.mode
categorical: M = mode (A)
categorical: [M, F] = mode (A)
categorical: [M, F, C] = mode (A)
categorical: […] = mode (A, dim)
categorical: […] = mode (A, vecdim)
categorical: […] = mode (A, 'all')
Most frequent element in a categorical array.
M = mode (A) returns the most frequent element in the
categorical vector A. If A is a matrix,
mode (A) returns a row vector with the most frequent element
from each column. For multidimensional arrays, mode (A)
operates along the first non-singleton dimension. B is also a
categorical array with the same categories as A. For multiple
elements with the same maximum frequency along the operating dimension,
the element from the category that occurs first in A is returned.
[M, F] = mode (A) also returns a numeric array
F, which has the same size as M and it contains the number of
occurrences of each corresponding element of M.
[M, F, C] = mode (A) also returns a cell
array C, which has the same size as M and each element is a
sorted categorical vector of all the values with the same maximum
frequency of the corresponding element of M.
B = mode (A, dim) operates along the dimension
specified by dim.
B = mode (A, vecdim) operates on all the
elements contained in the dimensions specified by vecdim, which
must be a numeric vector of non-repeating positive integers. Any values
in vecdim indexing dimensions larger that the actual array A
are ignored.
C = mode (A, operates on
all dimensions and returns the most frequent element in A.
[], 'all')
Source Code: categorical
mode returns the most frequent category. It is the one central-tendency statistic that also works for nominal arrays, since it counts occurrences rather than ranking them.
C = categorical ({'M'; 'S'; 'M'; 'L'; 'M'; 'S'})
C =
6x1 categorical array
M
S
M
L
M
S
mode (C)
ans = categorical M