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!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!