maxk

Returns maximum values.

Syntax

m = maxk(x, k)

m = maxk(x, k, dim)

[m,idx] = maxk(...)

Inputs

x
The matrix to query.
Type: double | complex | integer
Dimension: vector | matrix
k
The number of values to return.
Type: integer
Dimension: scalar
dim
The dimension on which to operate, or 'all'.
Default: first non-singleton dimension.
Type: int | string

Outputs

m
The k maximum values in each dimension.
Type: double
Dimension: scalar
idx
The index of each maximum value.
Type: integer
Dimension: scalar | vector | matrix

Examples

Vector example:

m = [4,12,9,3,8,10,2,7,6,11,5,-8];
[v,idx] = maxk(m, 5)
v = [Matrix] 1 x 5
12  11  10  9  8
idx = [Matrix] 1 x 5
2  10  6  3  5

Matrix example:

m = [4,12,9,3,8,10;2,7,6,11,5,-8];
[v,idx] = maxk(m, 5, 2)
v = [Matrix] 2 x 5
12  10  9  8  4
13  11  7  6  5
idx = [Matrix] 2 x 5
2  6  3  5  1
2  4  1  3  5

Comments

For a single operand, the function returns the maximum elements of each vector in the specified dimension. If the second output is requested, it contains the index of each maximum element.

NaN elements are ignored except when there are no numeric values to compare.