getting a NaN in correlation coefficient
Mostrar comentarios más antiguos
Hi, i have a simple problem which unfortunately i am unable to understand.
I have matrices and i am trying to calculate correlation coefficient between two variables. A simple example from my code is attched. Why am i getting a NaN here. What does this implies
x=[-7.501899598769999514e-04;-6.501899598769999514e-04;-5.501899598769999514e-04];
y=[-0.414;-0.414;-0.414];
c11=corr2(x,y)
Respuesta aceptada
Más respuestas (1)
Jan Pokorny
el 18 de Mzo. de 2021
Hi, I tried this funkcion as bellow, but it returns all NaN. I don't know why, any idea?
I then lately solved this by making cov() and then corrcov(), but it shouldn't go like that.
Data=[3 0 2 0 3 11 7 6 6 25 31 22 25 48 109 85 67 110 205 124 158 114 126 185 291 259 373 262 160 184 307 281 269 332 282 115 235 195 295];
for Zp=0:21
X=Data(1,1+Zp:39);
Y=Data(1,1:39-Zp);
RMat=corr(X,Y);
Koef(1+Zp)=RMat(1,2);
end
plot(0:Zp,Koef,'red*-')
1 comentario
Adam Danz
el 18 de Mzo. de 2021
From the documentation,
rho = corr(X,Y) returns a matrix of the pairwise correlation coefficient
between each pair of columns in the input matrices X and Y.
Note the word columns. You're using rows.
Instead,
RMat=corr(X(:),Y(:))
Categorías
Más información sobre Descriptive Statistics and Insights en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

