MATLAB: How to find indexes of 10 maximal valuse in a given NxN (symetric) matrix

matrixmaximal

I have a matrix which state (in each enterence (i,j)) the correlations of the (i,j) pair. I want the indexes of 10 pairs with maximal correlations. Any ideas? My matrix could get big so I am looking for the matlab elegant array/matrix commands (if there is any)
Thanks!

Best Answer

Always just try the straightforward solution first--
nMax=10;
[~,ix]=sort(c(:),1,'descend');
[i,j]=ind2sub(size(c),ix(1:nMax)); % keep top nMax, return locations in array
You can do things like keep values with X% of maximum in array to shrink the population drastically before sorting, etc., if the full-sized array turns out to be too time-consuming, but I'd just go "dead-ahead" until was shown to be a real bottleneck...