Zero correlation coefficient, example

This question of mine is not tightly related to Matlab, but is relevant to it:
I'm looking how to fill in this matrix in a few nontrivial ways
[[a,b,c],[d,e,f]] so that as many places in the ans of this matrix
corrcoef([a,b,c],[d,e,f])
are zero. My attempts yield NaN result in most cases.

댓글 수: 4

Jan
Jan 2021년 6월 13일
I'm still unable to obtain 0 in ans in my corrcoef matrix that avoids NaN.
The best I was able is to do this:
corrcoef([1,2,3];[-1,2,1])
Can anyone provide me with any example that creates 0 instead of NaN ?
I have both, the difficulty to create 0 in my Ans and understand the reasons provided in @Adam Danz Answer.
That line throws an error. There are two ways to correct it but you need to let us know which method fits your needs. See the corrcoef documentation to learn the difference between the two syntaxes.
Original line
corrcoef([1,2,3];[-1,2,1])
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
Corrected version 1
corrcoef([1,2,3],[-1,2,1])
ans =
1.0000 0.6547
0.6547 1.0000
Corrected version 2
corrcoef([1,2,3 ; -1,2,1])
ans =
1.0000 NaN 1.0000
NaN NaN NaN
1.0000 NaN 1.0000
Jan
Jan 2021년 6월 13일
편집: Jan 2021년 6월 13일
I need the second one.
x = [1,2,3 ; -1,2,1]
x = 2×3
1 2 3 -1 2 1
corrcoef computes the correlation coeficient for each pair of columns. Let's look at column 1 and 2
x(:,1), x(:,2)
ans = 2×1
1 -1
ans = 2×1
2 2
corr(x(:,1),x(:,2))
ans = NaN
Notice that x(:,2) contains the same values. Now look at the link in my answer and pay attantion to the part that says, "When each value of y is identical, the result is a vector of 0s. When you divide by zero, you get NaN. ".

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

답변 (1개)

Adam Danz
Adam Danz 2021년 6월 13일
편집: Adam Danz 2021년 6월 13일

0 개 추천

This answer explains why NaN values may appear in correlations.
Make sure your inputs avoid those errors. If you have trouble understanding the reasons explained in that answer or if you have trouble creating inputs that avoid NaNs after considering those reasons, share your inputs and we can help guide you in the right direction.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

Jan
2021년 6월 13일

편집:

2021년 6월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by