# min

Smallest element in array of `fi` objects

## Syntax

``x = min(a)``
``x= min(a,[],dim)``
``````[x,y] = min(___)``````
``m = min(a,b)``

## Description

example

````x = min(a)` returns the smallest elements along different dimensions of `fi` array `a`.If `a` is a vector, `min(a)` returns the smallest element in `a`.If `a` is a matrix, `min(a)` treats the columns of `a` as vectors, returning a row vector containing the minimum element from each column.If `a` is a multidimensional array, `min` operates along the first nonsingleton dimension and returns an array of minimum values.```

example

````x= min(a,[],dim)` returns the smallest elements along dimension `dim`.```

example

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

example

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

## Examples

collapse all

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

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

Create a matrix of fixed-point values.

`a = fi(magic(4),1,16)`
```a=4×4 object 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 smallest element of each row by finding the minimum values along the second dimension.

`x = min(a,[],2)`
```x=4×1 object 2 5 6 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```

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

Create a fixed-point matrix.

`a = fi(magic(4),1,16)`
```a=4×4 object 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 smallest element of each column.

`x = min(a)`
```x=1×4 object 4 2 3 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```

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

Find the index of each of the minimum elements.

`[x,y] = min(a)`
```x=1×4 object 4 2 3 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10 ```
```y = 1×4 4 1 1 4 ```

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 minimum elements from `a` or `b`.

`m = min(a,b)`
```m=2×3 object 2.2998 3.2100 1.6001 0 2.2998 1.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11 ```

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

Create a complex fixed-point vector, `a`.

`a = fi([1+2i,2+i,3+8i,9+i],1,8)`
```a=1×4 object 1.0000 + 2.0000i 2.0000 + 1.0000i 3.0000 + 8.0000i 9.0000 + 1.0000i DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 3 ```

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

`abs(a)`
```ans=1×4 object 2.2500 2.2500 8.5000 9.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 3 ```

In vector `a`, the smallest elements, at position `1` and `2`, have a magnitude of `2.25`. The `min` function returns the smallest element in output `x`, and the index of that element in output, `y`.

`[x,y] = min(a)`
```x = 1.0000 + 2.0000i DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 3 ```
```y = 1 ```

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

## Input Arguments

collapse all

`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 `min` function ignores `NaNs`.

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

Complex Number Support: Yes

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

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

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

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

## Algorithms

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

## Extended Capabilities

### HDL Code GenerationGenerate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™. 