# max

Largest element in array of `fi` objects

## Syntax

``M = max(A)``
``M = max(A,[],dim)``
``````[M,I] = max(___)``````
``C = max(A,B)``

## Description

example

````M = 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

````M = max(A,[],dim)` returns the largest elements along dimension `dim`.```

example

``````[M,I] = max(___)``` finds the indices of the maximum values and returns them in array `I`, 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

````C = max(A,B)` returns an array with the largest elements taken from `A` or `B`.```

## Examples

collapse all

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

```A = fi([1,5,4,9,2],1,16); M = max(A)```
```M = 9 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11 ```

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.

`M = max(A,[],2)`
```M = 16 11 12 15 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```

The output vector, M, is a column vector that contains the largest element of each 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 column.

`M = max(A)`
```M = 16 14 15 13 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```

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

Find the index of each of the maximum elements.

`[M,I] = max(A)`
```M = 16 14 15 13 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```
```I = 1×4 1 4 4 1 ```

Vector `I` contains the indices to the minimum elements in `M`.

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`.

`C = max(A,B)`
```C = 9.7998 4.7002 6.0000 3.1416 7.0000 9.2300 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11 ```

`C` contains the largest elements from each pair of corresponding elements in `A` and `B`.

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

collapse all

Input `fi` 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`

Complex Number Support: Yes

Additional input `fi` or numeric 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

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

collapse all

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

Index, returned as a scalar, vector, matrix, or multidimensional array. If the largest value occurs more than once, then `I` contains the index to the first occurrence of the value. `I` is always of data type `double`.

Maximum elements from `A` or `B`, returned as a scalar, vector, matrix, or multidimensional array.

## 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 built-in `max` function resolves ties between complex numbers.

## Version History

Introduced before R2006a