필터 지우기
필터 지우기

Find correlation between two matrices with varying NaN coordinates

조회 수: 11 (최근 30일)
Melissa
Melissa 2015년 5월 18일
답변: Chad Greene 2015년 5월 18일
Hello. I have global two matrices, A and B
They are both the same dimensions, but A has NaN's in some places that B does not. When I use corrcoef, it returns NaN's, even though the values within A and B are not identical. Is it returning NaN because the varying coordinates of NaN values within each matrix?
Does anyone know what I'm doing wrong in this case?
Thanks,
Melissa

답변 (1개)

Chad Greene
Chad Greene 2015년 5월 18일
Indeed,
A = [1 2 3 4 5 6 7];
B = [1 2 2 4 5 6 NaN];
corrcoef(A,B)
ans =
1 NaN
NaN NaN
But if you consider only non-NaN data:
% indices of non-nan data:
realz = isfinite(A) & isfinite(B);
% correlation coefficient of non-nan data:
corrcoef(A(realz),B(realz))
ans =
1.0000 0.9786
0.9786 1.0000

Community Treasure Hunt

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

Start Hunting!

Translated by