How to get second max element in matlab
Date: 2022-11-07 12:47:11
I have an array, say A = [ 3 5 6 7 ]
. I know I can get the maximum value of this array with max(A)
and it returns 7
, but how can I get the second max (6
) from this array without sorting or removing the first maximum value?
I have an array, say A = [ 3 5 6 7 ]
. I know I can get the maximum value of this array with max(A)
and it returns 7
, but how can I get the second max (6
) from this array without sorting or removing the first maximum value?
second_max_value = max(A(A~=max(A)))
Here A(A~=max(A))
will be temporary array that not contain maximal value of original array. Than you receive maximum of this array