Find correlation between two matrices with varying NaN coordinates
조회 수: 11 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!