maxLargest elements
NaN, the other number is returned. If both are NaN, it returns NaN.M = max(A)[M, I] = max(A)A is a scalar, M is equal to A.A is a vector, M is the largest element of A. NaN values in A are ignored when obtaining the maximum.A is a matrix or a multidimensional array, an element of M is equal to the largest element of the corresponding vector of A along its first non-singleton dimension. I is the position of that largest element in the direction of the non-singleton dimension.M = max(A, [ ], k)[M, I] = max(A, [ ], k)M corresponds to a vector of A along its k-th dimension.[] is the empty matrix.max(A, B)A and B should have compatible sizes.A and B, and returns the larger 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.a = randi(10,3,3,3)
% Finding maximum values along the 3rd dimension, stored in M.
% I stores the maxima's indexes along the 3rd dimension.
[M, I] = max(a,[],3)
a(:, :, 1) =
3.0000 10.000 4.0000
1.0000 4.0000 3.0000
2.0000 9.0000 10.000
a(:, :, 2) =
9.0000 4.0000 9.0000
9.0000 6.0000 3.0000
9.0000 3.0000 8.0000
a(:, :, 3) =
6.0000 5.0000 1.0000
3.0000 8.0000 6.0000
10.000 5.0000 2.0000
M =
9.0000 10.000 9.0000
9.0000 8.0000 6.0000
10.000 9.0000 10.000
I =
2.0000 1.0000 2.0000
2.0000 3.0000 3.0000
3.0000 1.0000 1.0000
a = randi(10,3,3)
b = randi(10,3,3)
max(a,b)
a =
3.0000 5.0000 1.0000
4.0000 5.0000 3.0000
2.0000 7.0000 3.0000
b =
5.0000 6.0000 4.0000
4.0000 5.0000 2.0000
4.0000 2.0000 7.0000
ans =
5.0000 6.0000 4.0000
4.0000 5.0000 3.0000
4.0000 7.0000 7.0000