Rearrange a correlation matrix into a vector and keep track of the corr names.

4 ビュー (過去 30 日間)
Hi All,
I have a large correlation matrix and I need to reshape the upper triangular (or lower triangular) information into a vector, which I can do as
ind = tril(true(size(Corr)),-1)
CorrVec = Corr(ind)
What I also need is to easily know the nature of the correlation when I will iterate over the vector: suppose
var1 var2 var3
Corr = var1 [ a b c
vare2 b e f
vare3 c f i ]
(a=e=i=1)
I want to get what is below (I m not interested on how the rearrangement is done, I just need the 3 info to have a one-to-one correspondence )
CorrVec = [ b c f ];
CorrVarFirst = ['var1' , 'var1','var2']
CorrVarSecond = [ 'var2', 'var3', 'var3']
In this way I can easily deduce that CorrVec(2) [c] is the correlation between CorrVarFirst(2) [var1] and CorrVarSecond(2) [var3]
Thanks in advance!

採用された回答

Turlough Hughes
Turlough Hughes 2021 年 12 月 8 日
編集済み: Turlough Hughes 2021 年 12 月 8 日
You can get the corresponding row and column indices as follows:
[iRow, iCol] = find(ind);
Then you can get the corresponding variable names as follows:
params = ["var1", "var2", "var3"];
disp(params(iRow))
disp(params(iCol))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by