max

Returns the maximum value of matrix.

Syntax

R = max(x)

R = max(x, [], dim)

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

R = max(x, y)

Inputs

x
The matrix to query.
Any valid scalar | vector | matrix
Type: double | integer | char | string | cell
Dimension: scalar | vector | matrix
y
The second matrix for a pairwise query with x.
Any valid scalar | vector | matrix
Type: double | integer | char | string | cell
Dimension: scalar | vector | matrix
dim
The dimension on which to search.
Default: first non-singleton dimension.
Type: double | integer | char | string | cell
Dimension: scalar

Outputs

R
The maximum value.
Type: double
Dimension: scalar
IDX
Index of max value.
Type: double
Dimension: scalar

Examples

Vector input with two outputs:

[a,b] = max([1,7,5])
a = 7
b = 2

Matrix input:

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

Matrix input with dimension:

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

Two matrix inputs:

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

Comments

For a vector input, it returns the maximum element. For a matrix input, it returns the maximum element from each vector in the direction of interest. If two outputs are requested, it returns a matrix containing the maximum from each element pair.