If A is a vector, then max(A) returns
the largest element of A.

If A is a matrix, then max(A) treats
the columns of A as vectors and returns a row vector
of largest elements.

If A is a multidimensional array,
then max(A) treats the values along the first array
dimension whose size does not equal 1 as vectors
and returns an array of maximum values. The size of this dimension
becomes 1 while the sizes of all other dimensions
remain the same.

M = max(A,[],dim) returns
the largest elements along dimension dim. For example,
if A is a matrix, then max(A,[],2) is
a column vector containing the maximum value of each row.

[M,I] =
max(___) finds the indices of the maximum values
of A and returns them in output vector I,
using any of the input arguments in the previous syntaxes. If there
are several identical maximum values, then max returns
the index of the first one.

C = max(A,B) returns
an array the same size as A and B with
the largest elements taken from A or B.
The dimensions of A and B must
match, or one can be a scalar.

To find the single largest element in a matrix, you can
apply the max function twice, max(max(A)).
However, this does not return the index to the largest element.

Use A(:) to find the maximum element in the
column representation of the elements from the array A.
Also return the index to the maximum element.

[M,I] = max(A(:))

M =
9
I =
2

A(:) is a column vector composed of all the
columns from the matrix, where each column is appended to the last. A(2) returns
the maximum element, 9.

Input array, specified as a scalar, vector, matrix, or multidimensional
array. A can be a numeric array, logical array,
ordinal categorical array, datetime array, or duration array.

Dimension to operate along, specified as a positive integer
scalar. If no value is specified, the default is the first array dimension
whose size does not equal 1.

Dimension dim indicates the dimension whose
length reduces to 1. The size(M,dim) is 1,
while the sizes of all other dimensions remain the same, unless size(A,dim) is 0.
If size(A,dim) is 0, then max returns
an empty array with the same dimension sizes.

Consider a two-dimensional input array, A:

If dim = 1, then max(A,[],1) returns
a row vector containing the largest element in each column.

If dim = 2, then max(A,[],2) returns
a column vector containing the largest element in each row.

Second input array, specified as a scalar, vector, matrix, or
multidimensional array. B can be a numeric array,
logical array, ordinal categorical array, datetime array, or duration
array.

The dimensions of A and B must
match, or one can be a scalar.

If A and B are ordinal
categorical arrays, they must have the same sets of categories, including
their order.

A and B can be the same
data type or one can be double and combine with single ,
any integer data type, or duration.

Maximum values, returned as scalar, vector, matrix, or multidimensional
array.

The size(M,dim) is 1,
while the sizes of all other dimensions match the size of the corresponding
dimension in A, unless size(A,dim) is 0.
If size(A,dim) is 0, then M is
an empty array with the same dimension sizes as A.

Index to A, returned as an array the same
size as A. If the largest element occurs more than
once, then I contains the index to the first occurrence
of the value.

The max function ignores NaNs.
When all elements in A are NaNs,
then max returns the first one as the maximum.
Undefined values in categorical arrays and NaT values
in datetime arrays are similar to NaNs in numeric
arrays.

When A is complex, the max function
returns the complex number with the largest complex modulus (magnitude).
If magnitudes are equal, then max returns the value
with the largest magnitude and the largest phase angle.

When you use max(A,B) with an empty array
and a scalar, then max returns an empty array.