How to calculate covariance matrix
15 次查看(过去 30 天)
显示 更早的评论
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 个)
Pratyush
2023-6-25
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!