Correlating Two Arrays Using Correcoef
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
>>
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!