I have two vectors:
A_1 =
10
200
7
150
A_2 =
0.001
0.450
0.0007
0.200
I would like to know if there is correlation between these two vectors.
I could subtract to each value the mean of the vector and than do:
A_1' * A_2
Are there any better ways?
Given:
(As others have already pointed out) There are tools to simply compute correlation, most obviously
corr:You can also use base Matlab’s
corrcoeffunction, like this:Which is closely related to the
covfunction:As you almost get to in your original question, you can scale and adjust the vectors yourself if you want, which gives a slightly better understanding of what is going on. First create a condition function which subtracts the mean, and divides by the standard deviation:
Then the correlation appears to be (A_1 * A_2)/(A_1^2), like this:
By symmetry, this should also work
And it does.
I believe, but don’t have the energy to confirm right now, that the same math can be used to compute correlation and cross correlation terms when dealing with multi-dimensiotnal inputs, so long as care is taken when handling the dimensions and orientations of the input arrays.