minSmallest elements
NaN, the other number is returned. If both are NaN, it returns NaN.M = min(A)[M, I] = min(A)A is a scalar, M is equal to A.A is a vector, M is the smallest element of A. NaN values in A are ignored when obtaining the minima.A is a matrix or a multidimensional array, an element of M is equal to the smallest element of the corresponding vector of A along its first non-singleton dimension. I is the position of that smallest element in the direction of the non-singleton dimension.M = min(A, [ ], k)[M, I] = min(A, [ ], k)M corresponds to a vector of A along its k-th dimension.[] is the empty matrix.min(A, B)A and B should have compatible sizes.A and B, and returns the smaller element.A and B have different but compatible sizes, one of the arguments will be expanded to match the size of the other argument. In particular, if one of the arguments is a scalar, this function compares the scalar with each element of the other argument.💡 When comparing two numbers by
min, if one of them isNaN, the other number is returned. If both areNaN, it returnsNaN.
a = randi(10,3,3,3)
% Finding minimum values along the 3rd dimension, stored in M.
[M, I] = min(a,[],3)
a(:, :, 1) =
9.0000 3.0000 1.0000
3.0000 9.0000 1.0000
10.000 2.0000 8.0000
a(:, :, 2) =
2.0000 7.0000 3.0000
1.0000 4.0000 8.0000
7.0000 1.0000 7.0000
a(:, :, 3) =
10.000 4.0000 6.0000
5.0000 2.0000 4.0000
10.000 3.0000 6.0000
M =
2.0000 3.0000 1.0000
1.0000 2.0000 1.0000
7.0000 1.0000 6.0000
I =
2.0000 1.0000 1.0000
2.0000 3.0000 1.0000
2.0000 2.0000 3.0000
a = randi(10,3,3)
b = randi(10,3,3)
min(a,b)
a =
9.0000 4.0000 1.0000
3.0000 6.0000 3.0000
3.0000 5.0000 2.0000
b =
3.0000 3.0000 5.0000
2.0000 2.0000 10.000
5.0000 10.000 8.0000
ans =
3.0000 3.0000 1.0000
2.0000 2.0000 3.0000
3.0000 5.0000 2.0000