Skip to Main Content Skip to Search
Product Documentation

min - Smallest elements in array

Syntax

C = min(A)
C = min(A,B)
C = min(A,[],dim)
[C,I] = min(...)

Description

C = min(A) returns the smallest elements along different dimensions of an array.

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.

C = min(A,B) returns an array the same size as A and B with the smallest elements taken from A or B. The dimensions of A and B must match, or they may be scalar.

C = min(A,[],dim) returns the smallest elements along the dimension of A specified by scalar dim. For example, min(A,[],1) produces the minimum values along the first dimension of A.

[C,I] = min(...) finds the indices of the minimum values of A, and returns them in output vector I. If there are several identical minimum values, the index of the first one found is returned.

Examples

Return the minimum of a 2-by-3 matrix from each column:

X = [2 8 4; 7 3 9];
min(X,[],1)
ans =

     2     3     4

Return the minimum from each row:

min(X,[],2)
ans =

     2
     3

Compare each element of X to a scalar:

min(X,5)
ans =

     2     5     4
     5     3     5

Tips

For complex input A, min returns the complex number with the smallest complex modulus (magnitude), computed with min(abs(A)). Then computes the smallest phase angle with min(angle(x)), if necessary.

The min function ignores NaNs.

See Also

max | mean | median | sort

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS