max

Returns maximum values.

Syntax

m = max(x)

m = max(x, [], dim)

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

m = max(x, y)

Inputs

x
The matrix to query.
Type: double | complex | integer
Dimension: scalar | vector | matrix
y
The second matrix for a pairwise query with x.
Type: double | complex | integer
Dimension: scalar | vector | matrix
dim
The dimension on which to operate, or 'all'.
Default: first non-singleton dimension.
Type: int | string

Outputs

m
The maximum values.
Type: double
Dimension: scalar
idx
The index of each maximum value. Not valid for a pairwise query.
Type: integer
Dimension: scalar | vector | matrix

Examples

Vector input with two outputs:

[m,idx] = max([1,7,5])
m = 7
idx = 2

Matrix input:

m = max([1,6;2,7])
m = [Matrix] 1 x 2
2 7

Matrix input with dimension:

m = max([1,6;2,5],[],1)
m = [Matrix] 1 x 2
2 6

Two matrix inputs:

m = max([1,6;2,5],[1,2;3,4])
m = [Matrix] 2 x 2
1  6
3  5

Comments

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

For two operands with common dimensions, the function returns the maximum element from each element pair. If an operand is a single element, it is compared with each element of the other operand.