finding n maximum elements in a matrix

1 view (last 30 days)
jenka
jenka on 6 Feb 2017
Edited: John Chilleri on 6 Feb 2017
Hi all, I have a symmetrical matrix of size mxm with diagonal elements equal to one. The values range [-1,1]. I would like to find five off the diagonal maximum elements in that matrix and return col and row indices. So far I have the following. It does not really work for values < 0. Any suggestions:
corrMat=rho - eye(size(rho));
A=corrMat;
sortedValues = unique(A(:));
maxValues = sortedValues(end-4:end);
  3 Comments
the cyclist
the cyclist on 6 Feb 2017
Also, do you want to select both the above- and below-diagonal instance of the maximal elements? Since the matrix is symmetric, there will always be pairs.
John Chilleri
John Chilleri on 6 Feb 2017
Edited: John Chilleri on 6 Feb 2017
If you want to base "maximum" on magnitude, then perhaps insert an
A = abs(corrMat); % A = corrMat;
but this will fail with the unique function if there is an equivalent negative/positive value.

Sign in to comment.

Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!