max

Purpose

Maximum elements of a matrix.

Synopsis

y = max(X)
[y,i] = max(X)
C = max(A,B)

Description

For vectors, max(X) is the largest element in X. For matrices, max(X) is a row vector containing the maximum element from each column and max(max(X)) is the largest element in the entire matrix.

[y,i] = max(X) stores the indices of the maximum values in vector i. If there are several identical maximum values, the index of the first one found is returned.

C = max(A,B) returns a matrix the same size as A and B with the largest elements taken from A or B.

For complex input X, max returns the complex number with the largest modulus, computed with max(abs(X)).

If any element of the matrix is a NaN, max returns NaN. To test for this occurrence, use the function isnan.

Examples

Start with A = magic(3):

A =
    8    1    6
    3    5    7
    4    9    2
Then max(A) is the vector

    8    9    7
and max(max(A)) is scalar

    9
Furthermore, [m,i] = max(A) produces

 m =
    8    9    7
          
 i =
    1    3    2

See Also

isnan, min, sort

(c) Copyright 1994 by The MathWorks, Inc.