How can I get the linear indices of the 4 maximum values of an array?

2 vues (au cours des 30 derniers jours)
Steven
Steven le 30 Jan 2023
I have an 20x1 array of numbers. I know I can use maxk to find the 4 highest values in the array, but if I want to get the linear index values of those 4 numbers how do I do that?
Example of what I mean:
A = [1 2 3 10 8 9 7 4 5 6];
maxk(A,4); gives [10 9 8 7]
If i want the linear indices of 10, 9, 8, and 7 without hardcoding, how can I do that?

Réponse acceptée

Arif Hoq
Arif Hoq le 30 Jan 2023
A = [1 2 3 10 8 9 7 4 5 6];
[B,Idx]=maxk(A,4)
B = 1×4
10 9 8 7
Idx = 1×4
4 6 5 7

Plus de réponses (0)

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by