Finding the indices of the maximum k elements (even if repeated)

3 views (last 30 days)
I have an array e.g A=[1 1 0 0 2 0 3 3 0 0] and would like to get the maximum 3 elements (even if repeated ) and their indices
Any help is highly appreciated. Thanks

Accepted Answer

Star Strider
Star Strider on 15 Jun 2021
One approach —
A=[1 1 0 0 2 0 3 3 0 0];
[Amax,idxmax] = maxk(A,3)
Amax = 1×3
3 3 2
idxmax = 1×3
7 8 5
See the documentation on maxk (introduced in R2017b) for details.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!