maxk
k largest elements of an array
📝 Syntax
B = maxk(A, k)
[B, I] = maxk(A, k)
B = maxk(A, k, dim)
📥 Input argument
A - numeric array (vector or matrix)
k - positive integer specifying how many largest elements to return
dim - optional dimension along which to operate (default: first non-singleton dimension)
📤 Output argument
B - array containing the k largest elements of A along the specified dimension
I - indices of the k largest elements with respect to A along the specified dimension
📄 Description
maxk returns the k largest elements of arrayA. When A is a vector, the result is the k largest values from A. When A is a matrix,maxk operates along the specified dimension (or the first non-singleton dimension by default) and returns the k largest elements for each slice along that dimension.
If k is larger than the number of available elements along the operating dimension, all elements are returned (sorted descending). When called as [B, I] = maxk(A, k),I contains the indices of the returned elements with respect to A.
💡 Examples
Vector example
Matrix example (along columns)
🔗 See also
mink.
🕔 History
1.15.0
initial version
Last updated
Was this helpful?