Correlating Two Arrays Using Correcoef

3 views (last 30 days)
James
James on 9 Apr 2019
Commented: James on 10 Apr 2019
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

Accepted Answer

dpb
dpb on 9 Apr 2019
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
>>

More Answers (0)

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!