Documentation Center

  • Trials
  • Product Updates

max

Largest elements in array

Syntax

  • C = max(A)
  • C = max(A,[],dim)
  • [C,I] = max(...)
  • C = max(A,B)

Description

C = max(A) returns the largest elements along different dimensions of an array.

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

If A is a matrix, max(A) treats the columns of A as vectors, returning a row vector containing the maximum element from each column.

If A is a multidimensional array, max(A) treats the values along the first non-singleton dimension as vectors, returning the maximum value of each vector.

C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension of A.

[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

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 they may be scalar.

Examples

Return the maximum of a 2-by-3 matrix from each column:

X = [2 8 4; 7 3 9];
max(X,[],1)
ans =

     7     8     9

Return the maximum from each row:

max(X,[],2)
ans =

     8
     9

Compare each element of X to a scalar:

max(X,5)
ans =

     5     8     5
     7     5     9

More About

expand all

Tips

For complex input A, max returns the complex number with the largest complex modulus (magnitude), computed with max(abs(A)). Then computes the largest phase angle with max(angle(x)), if necessary.

The max function ignores NaNs.

See Also

| | | |

Was this topic helpful?