Get the indices of the n largest elements in a matrix

前端 未结 4 2055
情书的邮戳
情书的邮戳 2020-11-27 15:46

Suppose I have the following matrix:

01 02 03 06
03 05 07 02
13 10 11 12
32 01 08 03

And I want the indices of the top 5 elements (in this

4条回答
  •  时光说笑
    2020-11-27 16:46

    In MATLAB ≥ R2017b, you can use maxk for this specific purpose.

    [maxvalues, ind] = maxk(A(:), 5);
    

提交回复
热议问题