maxk
Returns maximum values.
Syntax
m = maxk(x, k)
m = maxk(x, k, dim)
[m,idx] = maxk(...)
Inputs
- x
- The matrix to query.
- k
- The number of values to return.
- dim
- The dimension on which to operate, or 'all'.
Outputs
- m
- The k maximum values in each dimension.
- idx
- The index of each maximum value.
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.