Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Largest elements

returns
the largest elements of matrix `C`

= max(`A`

,[],`dim`

)`A`

along the dimension `dim`

.
Thus, `max(A,[],1)`

returns a row vector containing
the largest elements of each column of `A`

, and `max(A,[],2)`

returns
a column vector containing the largest elements of each row of `A`

.

Here, the required argument `[]`

serves as
a divider. If you omit it, `max(A,dim)`

compares
elements of `A`

with the value `dim`

.

Find the largest of these numbers. Because these numbers are not symbolic objects, you get a floating-point result.

max([-pi, pi/2, 1, 1/3])

ans = 1.5708

Find the largest of the same numbers converted to symbolic objects.

max(sym([-pi, pi/2, 1, 1/3]))

ans = pi/2

Create matrix `A`

containing
symbolic numbers, and call `max`

for this matrix.
By default, `max`

returns the row vector containing
the largest elements of each column.

A = sym([0, 1, 2; 3, 4, 5; 1, 2, 3]) max(A)

A = [ 0, 1, 2] [ 3, 4, 5] [ 1, 2, 3] ans = [ 3, 4, 5]

Create matrix `A`

containing
symbolic numbers, and find the largest elements of each row of the
matrix. In this case, `max`

returns the result
as a column vector.

A = sym([0, 1, 2; 3, 4, 5; 1, 2, 3]) max(A,[],2)

A = [ 0, 1, 2] [ 3, 4, 5] [ 1, 2, 3] ans = 2 5 3

Create matrix `A`

. Find the
largest element in each column and its index.

A = 1./sym(magic(3)) [Cc,Ic] = max(A)

A = [ 1/8, 1, 1/6] [ 1/3, 1/5, 1/7] [ 1/4, 1/9, 1/2] Cc = [ 1/3, 1, 1/2] Ic = 2 1 3

Now, find the largest element in each row and its index.

[Cr,Ir] = max(A,[],2)

Cr = 1 1/3 1/2 Ir = 2 1 3

If `dim`

exceeds the number of dimensions
of `A`

, then the syntax `[C,I] = max(A,[],dim)`

returns ```
C
= A
```

and `I = ones(size(A))`

.

[C,I] = max(A,[],3)

C = [ 1/8, 1, 1/6] [ 1/3, 1/5, 1/7] [ 1/4, 1/9, 1/2] I = 1 1 1 1 1 1 1 1 1

Create matrices `A`

and `B`

containing
symbolic numbers. Use `max`

to compare each element
of `A`

with the corresponding element of `B`

,
and return the matrix containing the largest elements of each pair.

A = sym(pascal(3)) B = toeplitz(sym([pi/3 pi/2 pi])) maxAB = max(A,B)

A = [ 1, 1, 1] [ 1, 2, 3] [ 1, 3, 6] B = [ pi/3, pi/2, pi] [ pi/2, pi/3, pi/2] [ pi, pi/2, pi/3] maxAB = [ pi/3, pi/2, pi] [ pi/2, 2, 3] [ pi, 3, 6]

When finding the maximum of these complex numbers, `max`

chooses
the number with the largest complex modulus.

modulus = abs([-1 - i, 1 + 1/2*i]) maximum = max(sym([1 - i, 1/2 + i]))

modulus = 1.4142 1.1180 maximum = 1 - 1i

If the numbers have the same complex modulus, `min`

chooses
the number with the largest phase angle.

modulus = abs([1 - 1/2*i, 1 + 1/2*i]) phaseAngle = angle([1 - 1/2*i, 1 + 1/2*i]) maximum = max(sym([1 - 1/2*i, 1/2 + i]))

modulus = 1.1180 1.1180 phaseAngle = -0.4636 0.4636 maximum = 1/2 + 1i

Was this topic helpful?