Get the indices of the n largest elements in a matrix

前端 未结 4 2008
情书的邮戳
情书的邮戳 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:38

    You can find good answers to matlab questions also on matlabcentral. I found a good mex implementation there while searching for the same thing.

    It is done by Bruno Luong using a partial quick-sort algorithm implemented with C-MEX. The complexity is O(n + k.log(k)), where n is the size of the array, and k is the number of elements to be selected. It is faster than SORT or multiple call of MIN/MAX for large size inputs. Multidimensional capability supported

    http://www.mathworks.com/matlabcentral/fileexchange/23576-minmax-selection

提交回复
热议问题