corr(x,y) nan

4 ビュー (過去 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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by