How to find second largest OR third largest Or any largest value among the columns of a matrix?

I have a matrix A=rand(7,25)
I want to find the second largest/third largest/fourth/fifth and sixth largest value among all the columns of matrix "A". No need of seventh largest as there are total 7 values in each column.
Thank you.

 Accepted Answer

A=rand(7,25)
[aa,indices]=sort(A,'descend')

4 Comments

Sorry, i forgot to mention, I also want to save their indices in an array also.
i.e. I want to save indices for max value among columns in one array, then indices for second largest value in another array.
Kindly help
They're all in indices. Why do you need different arrays??? If you do, just do
maxIndexes = indices(1,:);
max2Indexes = indices(2,:);
max3Indexes = indices(3,:);
and so on.
Thanks very much. This is a good one - it gives correct indices of the original array for any max

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!