Correlation computation using a window of 3
2 views (last 30 days)
Show older comments
Tino on 17 Aug 2020
Commented: Tino on 18 Aug 2020
Please I have 3 column x, and y
x = 5, 8, 9, 4, 9, 6, 0 ,7 ,8 , 5, 4
y = 6, 4, 8, 7, 3, 7, 8 ,7 ,6 , 4, 7
I want to find the correlation using 3 window size computation
for instance the first 3 windows will be corr for x = 5, 8 , 9 and y = 6, 4, 8
The if the last numbers is not equal to 3 then the correlation of the numbers present is obtained in the case of
The cor for x = 5, 4 and y = 4, 7 is obtained
I get a new column for x and y with 4 rows
I need a value for the correlation instead of the corrcoef function which is giving me matrices.
Thanks for your help in advance.
Dana on 17 Aug 2020
I don't entirely understand what you're trying to do, but you may want to use corr(a,b) instead of corrcoef(a,b) or corrcoef(C).
For a matrix C, corrcoef(C) returns a correlation matrix, i.e., a matrix whose (i,j) element is the correlation coefficient between the i-th and j-th columns of C. For column vectors a and b, the syntax corrcoef(a,b) is the same thing as corrcoef([a,b]) (i.e., MATLAB just puts the two vectors together into a single matrix, and then finds the correlation matrix).
On the other hand, corr(a,b) simply returns the correlation coefficient between the vectors a and b. Note, however, that corr([a,b]) = corrcoef(a,b) = corrcoef([a,b]), i.e., that syntax will also return the correlation matrix. So if you just want the one correlation coefficient, you need to use corr(a,b).
More Answers (0)
Find more on Correlation and Convolution 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!