corr(x,y) nan

조회 수: 3 (최근 30일)
Vishal Thakkar
Vishal Thakkar 2019년 8월 15일
편집: Image Analyst 2019년 8월 16일
Hello, I am trying to run a correlation using corr(x,y), but my dataset has NaNs in it, for different participants (beginner coder here).
For example, my dataset and code may look like this:
a = [78 88 87 54 68 91 72 nan 88 nan];
b = [nan 35 42 44 67 55 nan 34 25 33];
x = ~isnan(a);
y = ~isnan(b);
[r,p] = corr(x,y)
The result is a table full of NaN in the ouptut.
I am trying to get the r value and the p value. Would there be another way to achieve this?

채택된 답변

Michael
Michael 2019년 8월 15일
편집: Michael 2019년 8월 15일
I think you are looking for corrcoef instead of corr. To exclude the nan values, use
a = [78 88 87 54 68 91 72 nan 88 nan];
b = [nan 35 42 44 67 55 nan 34 25 33];
r = corrcoef(a,b, 'rows','complete')
  댓글 수: 2
madhan ravi
madhan ravi 2019년 8월 15일
You forgot to provide the function in the last line.
Michael
Michael 2019년 8월 15일
Ups, I'm sorry. I edited my posting.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by