categorical

Methods

Method Reference: categorical.maxk

categorical: B = maxk (A, K)
categorical: B = maxk (A, K, dim)
categorical: [B, index] = maxk (A, …)

Find the largest elements in an ordinal categorical array.

B = maxk (A, K) returns the K largest elements of the categorical array A in descending order. A must be ordinal, since the elements are ranked by the order of their categories. If A is a vector, then B is a vector with K elements. If A is a matrix, then maxk operates along each column of A and B has K rows. For multidimensional arrays, maxk operates along the first non-singleton dimension. B keeps the categories of A, including their order.

B = maxk (A, K, dim) operates along the dimension specified by dim.

K must be a nonnegative integer scalar. If K is larger than the number of elements along the operating dimension, then all of them are returned.

Missing elements (<undefined>) are not ranked. They are appended after the ranked elements in their original order, and hence they only appear in B when K exceeds the number of defined elements along the operating dimension. Unlike sort, maxk has no 'MissingPlacement' option, since undefined elements are always placed last. Elements comparing as equal keep their original order.

[B, index] = maxk (A, …) also returns an index array containing the indices of the returned elements of A along the operating dimension.

Source Code: categorical