简体   繁体   English

GNU Octave/Matlab:如何获取数组中三个最大值的索引?

[英]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?假设我有一个数组A = [ 41 13 22 18 32]如何获得三个最大值的索引?

In this example I expect to get 1,5,3 (indexes of 41,32,22).在这个例子中,我希望得到 1,5,3(索引为 41,32,22)。

Thanks!谢谢!

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它可以在线使用 Octave

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM