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

5 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Turlough Hughes
Turlough Hughes le 8 Déc 2021
Modifié(e) : Turlough Hughes le 8 Déc 2021
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))

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by