Main Content

min

Smallest element in array of fi objects

Description

example

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

M = min(A,[],dim) returns the smallest elements along dimension dim.

example

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

C = min(A,B) returns an array 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);
M = min(A)
M = 
     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 = 
    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.

M = min(A,[],2)
M = 
     2
     5
     6
     1

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

The output, M, 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 = 
    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.

M = min(A)
M = 
     4     2     3     1

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

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

Find the index of each of the minimum elements.

[M,I] = min(A)
M = 
     4     2     3     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 10
I = 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.

C = min(A,B)
C = 
    2.2998    3.2100    1.6001
         0    2.2998    1.0000

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

C 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.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 min function finds the smallest element of a complex vector by taking the element with the smallest magnitude.

abs(A)
ans = 
    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 M, and the index of that element in output, I.

[M,I] = min(A)
M = 
   1.0000 + 2.0000i

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 3
I = 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 or numeric 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

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 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. M always has the same data type as the input.

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

Minimum elements from A or 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 built-in min function resolves ties between complex numbers.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a

See Also

| | |