我如何在scilab的矩阵中保存前4个最大数的索引

问题描述 投票:0回答:2

我需要保存4个最大数字的索引例如,我需要获取第10,9,7,5行的索引

5.0259327
4.7127487
4.8435524
4.8538644
5.1048996
6.2441973
5.9413803
6.2912638
5.1117512
5.8309519
5.7419509
6.9663477
5.9958319
6.9519781
6.5802736
6.7327558
7.6765878

我用过

[mA,nA]=max(distA) 
where mA is the row and nA is the column

获得一个最大数量,但我不知道如何选择另一个最大数量而不重复。我无法排序,因为我需要索引。

matlab scilab
2个回答
0
投票

您可以使用这个小把戏。

 [output_val, output_index] = max(input_mat(input_mat < max(input_mat)))

这将为您提供第二大元素的值和索引。然后类似地,您可以对4个数字进行处理。


1
投票

您可以使用gsort函数:

 [S,ind]=gsort(distA,"g","d");

最大的四个元素的索引由]给定>

 ind(1:4)
© www.soinside.com 2019 - 2024. All rights reserved.