mink

The k smallest elements of an array, in ascending order.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

B = mink(A, k)

The k smallest values along the first non-singleton dimension.

B = mink(A, k, dim)

Along dimension dim.

[B, I] = mink(___)

Also returns the indices of those values in A.

Description

mink is the counterpart of maxk. Ties are listed in the order they appear in A, so with two equal values the one with the smaller index comes first.

For a matrix the result holds the k smallest values of each column; use dim = 2 to work along rows.

Input arguments

A
Numeric array.
k
How many values to return.
dim
Dimension to operate along.

Output arguments

B
The k smallest values, sorted from smallest to largest.
I
Indices into A of the values in B.

Example

Three smallest values

x = [3 1 4 1 5 9 2 6 5 3];
[B, I] = mink(x, 3)
Output
B = 1×3

     1     1     2
I = 1×3

     2     4     7

See also

maxk min sort bounds