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

5 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 8 de Dic. de 2021
Editada: Turlough Hughes el 8 de Dic. de 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))

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by