MATLAB: Finding largest values in matrix

matrixmax

I would like to find the 10 largest values in a 90×90 matrix, and their indices. Any suggestions? Thanks, Yaniv

Best Answer

A = randn(90);
Nmax = 10; % get Nmax biggest entries
[ Avec, Ind ] = sort(A(:),1,'descend');
max_values = Avec(1:Nmax);
[ ind_row, ind_col ] = ind2sub(size(A),Ind(1:Nmax)); % fetch indices
You can of course also use a while loop and pick out one value at a time.