Tony YEe
Tony YEe

Reputation: 235

Find the top 5 highest number in an matrix of 4x5

There are 12 numbers present in an 4x3 matrix and I need to find out the top 5 highest numbers among them. For example,

B=[11 13 21;10 8 5;3 2 6;7 18 6]

Thus the top 5 highest numbers should be

ans=[21;18;13;11;10]

How could I go about doing it?

Upvotes: 0

Views: 931

Answers (1)

devrobf
devrobf

Reputation: 7213

Sort the data:

Bsorted = sort(B(:), 'descend');

And pick the top 5:

Btop5 = Bsorted(1:5);

Upvotes: 2

Related Questions