Correlation between two row matrices

조회 수: 3 (최근 30일)
Bhaskar R
Bhaskar R 2019년 5월 9일
댓글: gonzalo Mier 2019년 5월 9일
I am trying to do correlation between two row matrices but i am getting all NaN?
a = [-1 -1 -1 -1 -1 1 1 1 1 1];
b = randn(1,10);
result = corr(a, b);
result =
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

채택된 답변

gonzalo Mier
gonzalo Mier 2019년 5월 9일
Like that, each value of "a" is correlated to each value of "b", but applying the formula of the correlation, the correlation of two single numbers is NaN. To compute the correlation correctly, traspose the input vectors
result = corr(a', b');
  댓글 수: 2
Bhaskar R
Bhaskar R 2019년 5월 9일
Thank you gonzalo Mier
gonzalo Mier
gonzalo Mier 2019년 5월 9일
You're welcome :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by