lucullus
lucullus

Reputation: 217

GNU Octave/Matlab: How to get the index of the three biggest values in an array?

Let's say I have an array A = [ 41 13 22 18 32] How can I get the indexes of the three greatest values?

In this example I expect to get 1,5,3 (indexes of 41,32,22).

Thanks!

Upvotes: 0

Views: 520

Answers (1)

YevKad
YevKad

Reputation: 680

According to this documentation:

A = [ 41 13 22 18 32];
[val idx]=sort(A,'descend');
top3_idx=idx(1:3)

It works in Octave online

Upvotes: 4

Related Questions