I'm calculating the correlation coefficient between two vectors, using corr. It returns NaN, and I'm curious to know why that is the case.
c and d are the vectors.
>> [c d]
ans =
1 1
2 1
2 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
2 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

 채택된 답변

Sean de Wolski
Sean de Wolski 2011년 7월 7일

4 개 추천

read the:
doc corr
and you'll see it's not what you want. Are you looking for :
doc corrcoef %?

댓글 수: 3

D
D 2011년 7월 7일
Yes, thank you. But I still get
corrcoef(c,d)
ans =
1 NaN
NaN NaN
This seems to point at something in d as being an issue.
Sean de Wolski
Sean de Wolski 2011년 7월 7일
It's because there's no variance/ standard deviation in the second column and thus in the correlation coefficient calculation when you divide by std or var (however it's implemented) you're in turn dividing zero by zero which yield nan.
D
D 2011년 7월 7일
Thank you. I missed that.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bio_Ing_Sapienza
Bio_Ing_Sapienza 2019년 2월 24일

1 개 추천

Maybe you have to ceck for "Inf" components in your array. Sometimes I was searching from Nan even if I had already checked them out. But there are other kind of Matlab numeric representation for results came from division that yields to too large numbers to be represented with floating number. So check also for these ones!

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

질문:

D
D
2011년 7월 7일

답변:

2019년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by