finding n maximum elements in a matrix

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 件のコメント

Adam
Adam 2017 年 2 月 6 日
What aspect of it doesn't work for negative numbers? You mean you want -1 to be considered greater than -0.5?
the cyclist
the cyclist 2017 年 2 月 6 日
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 2017 年 2 月 6 日
編集済み: John Chilleri 2017 年 2 月 6 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2017 年 2 月 6 日

編集済み:

2017 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by