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
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