Correlation

조회 수: 4 (최근 30일)
Salvatore Turino
Salvatore Turino 2012년 1월 25일
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).

답변 (2개)

Sean de Wolski
Sean de Wolski 2012년 1월 25일
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
Salvatore Turino
Salvatore Turino 2012년 1월 25일
uhm if i do corrcoef(1,1) i expect 1 instead i got NaN, instead if i do corrcoef([1,2],[1,5]) i got a matrix...that is also strange since i have as result:
1.0000 1.0000
1.0000 1.0000
can you explain me how to interpretate this result?i mean what is the element 11, 12, 21 and 22 of this matrix?

댓글을 달려면 로그인하십시오.


Salvatore Turino
Salvatore Turino 2012년 1월 25일
ok but if i need the correlation of two scalar how can i do it?what i need is the simple correlation index of Pearson.
so a value that is around 0 or 1.
doing
corrcoef(1:10,10:-1:1)
at the end i obtain always a matrix 2x2 and i can't watch the correlation of the single values.
  댓글 수: 5
Salvatore Turino
Salvatore Turino 2012년 1월 25일
well from what my teacher told me i need to know how different is 1 from 3 or 1 from 2, and he told me to use the correlation.
Sean de Wolski
Sean de Wolski 2012년 1월 25일
oh. I would use a difference (minus).
3 - 1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by