Documentation

max

Largest element in array of fi objects

Syntax

Description

example

x = max(a) returns the largest elements along different dimensions of fi array a.

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 operates along the first nonsingleton dimension and returns an array of maximum values.

example

x= max(a,[],dim) returns the largest elements along dimension dim.

example

[x,y] = max(___) finds the indices of the maximum values and returns them in array y, using any of the input arguments in the previous syntaxes. If the largest value occurs multiple times, the index of the first occurrence is returned.

example

m = max(a,b) returns an array the same size as a and b with the largest elements taken from a or b.

Examples

expand all

Largest Element in a Vector

Create a fixed-point vector, and return the maximum value from the vector.

a = fi([1,5,4,9,2],1,16);
x = max(a)
x = 

     9

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 11

Largest Element of Each Matrix Row

Create a fixed-point matrix.

a = fi(magic(4),1,16)
a = 

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10

Find the largest element of each row by finding the maximum values along the second dimension.

x = max(a,[],2)
x = 

    16
    11
    12
    15

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10

The output vector, x, is a column vector that contains the largest element of each row.

Largest Element of Each Matrix Column

Create a fixed-point matrix.

a = fi(magic(4),1,16)
a = 

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10

Find the largest element of each column.

x = max(a)
x = 

    16    14    15    13

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10

The output, x, is a row vector that contains the largest elements from each column of a.

Find the index of each of the maximum elements.

[x,y] = max(a)
x = 

    16    14    15    13

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10

y =

     1     4     4     1

Vector y contains the indices to the minimum elements in x.

Maximum Elements from Two Arrays

Create two fixed-point arrays of the same size.

a = fi([2.3,4.7,6;0,7,9.23],1,16);
b = fi([9.8,3.21,1.6;pi,2.3,1],1,16);

Find the largest elements from a or b.

m = max(a,b)
m = 

    9.7998    4.7002    6.0000
    3.1416    7.0000    9.2300

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 11

m contains the largest elements from each pair of corresponding elements in a and b.

Largest Element of a Complex Vector

Create a complex fixed-point vector, a.

a = fi([1+2i,3+6i,6+3i,2-4i],1,16)
a = 

   1.0000 + 2.0000i   3.0000 + 6.0000i   6.0000 + 3.0000i   2.0000 - 4.0000i

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

The function finds the largest element of a complex vector by taking the element with the largest magnitude.

abs(a)
ans = 

    2.2361    6.7083    6.7083    4.4722

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

In vector a, the largest elements, at position 2 and 3, have a magnitude of 6.7083. The max function returns the largest element in output x and the index of that element in output y.

[x,y] = max(a)
x = 

   3.0000 + 6.0000i

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

y =

     2

Although the elements at index 2 and 3 have the same magnitude, the index of the first occurrence of that value is always returned.

Input Arguments

expand all

a — Input fi arrayfi object | numeric variable

fi input array, specified as a scalar, vector, matrix, or multidimensional array. The dimensions of a and b must match unless one is a scalar.

The max function ignores NaNs.

Data Types: fi|single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Complex Number Support: Yes

b — Second input fi arrayfi object | numeric variable

Second fi input array, specified as a scalar, vector, matrix, or multidimensional array. The dimensions of a and b must match unless one is a scalar.

The max function ignores NaNs.

Data Types: fi|single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Complex Number Support: Yes

dim — dimension to operate alongpositive integer scalar

Dimension to operate along, specified as a positive integer scalar. dim can also be a fi object. If you do not specify a value, the default value is the first array dimension whose size does not equal 1.

Data Types: fi|single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

expand all

x — Maximum valuesscalar | vector | matrix | multidimensional array

Maximum values, returned as a scalar, vector, matrix, or multidimensional array. x always has the same data type as the input.

y — Index of maximum valuesscalar | vector | matrix | multidimensional array

Indices of the maximum values in array x, returned as a scalar, vector, matrix, or multidimensional array. If the largest value occurs more than once, then y contains the index to the first occurrence of the value. y is always of data type double.

m — Array of maximum valuesscalar | vector | matrix | multidimensional array

Array of maximum values of a and b, returned as a scalar, vector, matrix, or multidimensional array.

More About

expand all

Algorithms

When a or b is complex, the max function returns the elements with the largest magnitude. If two magnitudes are equal, then max returns the first value. This behavior differs from how the builtin max function resolves ties between complex numbers.

See Also

| | |

Was this topic helpful?