Correlating Two Arrays Using Correcoef

3 ビュー (過去 30 日間)
James
James 2019 年 4 月 9 日
コメント済み: James 2019 年 4 月 10 日
I am attempting to correlate two arrays using function = corrcoef. When I employ the function, I end up with a matrix that looks like the one below. The arrays are the same size. What could be the reason for the error? When I plot them as a scatter, there is clearly little correlation, but it would be nice to know the correlation coeffecient.
R_32 =
1 NaN
NaN NaN

採用された回答

dpb
dpb 2019 年 4 月 9 日
There's at least one NaN in the second variable...you don't give any information about which is which.
>> spd=5*rand(500,1);tlt=randn(500,1)/5;
>> scatter(tlt,spd)
>> corrcoef(tlt,spd)
ans =
1.00 0.06
0.06 1.00
>> spd(1)=nan;
>> corrcoef(tlt,spd)
ans =
1.00 NaN
NaN NaN
>>
NaN values are just silently ignored by plot routines so that won't show up anything unusual...use the 'rows' optional parameter to skip NaN in the input...
>> corrcoef(tlt,spd,'rows','complete')
ans =
1.00 0.06
0.06 1.00
>>
  1 件のコメント
James
James 2019 年 4 月 10 日
Thank You!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by