Correlation
Show older comments
Hello who i can do the correlation between two numbers? thank you
[EDIT SCd - moved answer to question]
i've seen that there is the function corrcoef(x,y) but i want to know if i have an x and an y vector of the same size does this function correlate each x(i) element with the y(i) at the same position? to be clear i need the correlation of x(1) with y(1), x(2) with y(2)..x(n) with y(n).
Answers (2)
Sean de Wolski
on 25 Jan 2012
Yes. It does.
A good example:
corrcoef(1:10,10:-1:1)
More:
corrcoef when called with two scalars or vectors produces a 2x2 matrix. The diagonal of the matrix is the correlation of the two vectors to themselves. These should always be 1 (unless there is a nan or an inf).
The antidiagonal is each vector's correlation to each other.
so corrcoef(x,y) will be: [x2x, x2y; y2x y2y]
These are the values you are most likely after. Scalars will always be perfectly correlated to each other. If I give pi and 42 to corrcoef for the data provided they are perfectly correlated (as is pi and -42 or any other number out there!). The same is true for 2 element vectors except there is an addition of sign, e.g:
corrcoef([1,2],[1,1000])
versus
corrcoef([1,2],[1,-1000])
1 Comment
Salvatore Turino
on 25 Jan 2012
Salvatore Turino
on 25 Jan 2012
0 votes
5 Comments
Sean de Wolski
on 25 Jan 2012
Unless there is a nan,inf or two zeros, the correlation between two scalars will always b1. You could also, always exctract the component of the 2x2 matrix that you need. I explained what each was above.
Salvatore Turino
on 25 Jan 2012
Tom Lane
on 25 Jan 2012
I'm not sure what you want. How different is 1 from 3?
Normally correlation requires a sequence of numbers. But even then, you're measuring how much they vary in tandem, not how their specific values differ.
Salvatore Turino
on 25 Jan 2012
Sean de Wolski
on 25 Jan 2012
oh. I would use a difference (minus).
3 - 1
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!