How to calculate covariance matrix

32 views (last 30 days)
yusuf zain
yusuf zain on 13 Sep 2018
Answered: Pratyush on 25 Jun 2023
I have many datasets for PCA calculations, because the data is too large for the matrix covariance calculation. how can the results of the covariance matrix be stored in several matrix so that they are not too large if stored in one matrix? or is there another way to be able to calculate eigenvalues without manually looking for the covariance value of the matrix?
  1 Comment
hossein najafi
hossein najafi on 18 May 2019
hi
I have the same problem. Could you find the solution?

Sign in to comment.

Answers (1)

Pratyush
Pratyush on 25 Jun 2023
Hi Yusuf.
It is my understanding that you have a large dataset and you would like to store the covariance of each field against the other in several matrices instead of one. Here is how we can achieve it.
MATLAB has a function named "cov" that returns the covariance based on what is passed as parameters to the function. Say we have two vectors a and b. Then cov(a,b) computes the covariance matrix of the two vectors which is a 2x2 matrix. The individual entries of the matrix have the following meaning.
cov(a,a) cov(a,b)
cov(b,a) cov(b,b)
The entry on the first row and second column is the covariance between the two vectors a and b.
In the case with large dataset, we can iteratively compute the covariances between all possible pairs of fields and store them as separately. For example in one vector we can store the covariances of the first field with all other fields. In the second vector we can store the covariances of the second field with all other fields, and so on.
Hope this resolves your problem.
Here is the documentation on the cov function in MATLAB.

Community Treasure Hunt

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

Start Hunting!