mink
k smallest elements of an array
📝 Syntax
B = mink(A, k)
[B, I] = mink(A, k)
B = mink(A, k, dim)
📥 Input argument
A - numeric array (vector or matrix)
k - positive integer specifying how many smallest elements to return
dim - optional dimension along which to operate (default: first non-singleton dimension)
📤 Output argument
B - array containing the k smallest elements of A along the specified dimension
I - indices of the k smallest elements with respect to A along the specified dimension
📄 Description
mink returns the k smallest elements of arrayA. When A is a vector, the result is the k smallest values from A. When A is a matrix,mink operates along the specified dimension (or the first non-singleton dimension by default) and returns the k smallest 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 ascending). When called as [B, I] = mink(A, k),I contains the indices of the returned elements with respect to A.
💡 Examples
Vector example
Matrix example (along columns)
🔗 See also
maxk.
🕔 History
1.15.0
initial version
Last updated
Was this helpful?