min
Smallest element, along a dimension, or the smaller of two arrays.
Category: Language Fundamentals > Data Types
Syntax
M = min(A)
Smallest element of a vector, or of each column of a matrix.
[M, I] = min(A)
Also returns the index of the smallest element; the first one when there are ties.
M = min(A, [], dim)
Smallest along dimension dim.
M = min(A, [], 'all')
Smallest of all elements.
M = min(A, B)
Element-wise smaller of A and B, with implicit expansion.
Description
min mirrors max. NaN values are ignored unless every value is NaN, so min([4 NaN 2]) is 2. Integer types keep their class, and the empty matrix gives [].
With one output the first minimum wins on ties; with the two-array form there is no index output.
Input arguments
A, B- Numeric, logical or char arrays, or datetime or duration arrays.
dim- Dimension to work along.
'omitnan' | 'includenan'- Whether NaN values are skipped (the default) or make the result NaN.
Output arguments
M- The smallest values.
I- Indices of the minima along the working dimension.
Example
Minima of a matrix
A = [1 5; 7 2];
min(A)
min(A, [], 2)
[m, i] = min([3 1 2 1])
min([4 NaN 2])
min(int8([5 -3 9]))
Output
ans = 1×2
1 2
ans = 2×1
1
2
m = 1
i = 2
ans = 2
ans = int8
-3