Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

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 

 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com