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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by