covariance matrix from a random vector?
Mostrar comentarios más antiguos
Given a random vector, Y=[y1,y2,...,yn]; its covariance matrix look like this:

According to this definition, How can I calculate covariance matrix in matlab? N.B. cov() function makes me confusion....
Respuesta aceptada
Más respuestas (3)
Christopher Smith
el 28 de En. de 2018
1 voto
I know this question is old but I came across this page looking for the same answer. If the cov() function in Matlab had an input element option for the expected value of the two functions then it would work but it does not. The cov() function appears to be designed for a large data set where the mean value can be determined. In your case you will need to know the expected value of each of the random variables in your vector ahead of time. Then the covariance of that vector would be calculated with nested for loops iterating through the array and computing the elementwise covariance manually. The built in function cov() does not provide any options here. This is the video link that helped me: https://m.youtube.com/watch?v=0W8hTzU1ZMM It assumes that you have a vector of random variable values (instances) where each element represents the functions to be compared with covariance and that for each element in the vector you already know the expected value. Then it is easy to take an Nx1 vector and compute the NxN covariance matrix but tedious.
1 comentario
Anna M
el 3 de Jul. de 2019
I am also looking for the same answer, and that video helped a lot! Thanks
Roger Stafford
el 27 de Oct. de 2016
0 votos
With just a vector, Y, you can calculate its variance but there is no significance to calculating its covariance. That would always be zero.
Covariance has a significance only with a set of vectors. Matlab’s ‘cov’ function will obtain the covariance of a matrix where the different columns are different components of random variables and the rows are different variations of those rows. Applied to your problem, the result would be a row of zeros since there is no variation (though that is not what matlab does). If you start with a single column vector the result is simply the variance which will be a scalar.
1 comentario
K M Ibrahim Khalilullah
el 2 de Nov. de 2016
Allen Goldstein
el 3 de Abr. de 2021
Let me see if I have this right, if I run cov(z) where z is a vector, I'll just get a vector. The covarinace matrix has the variances (cov(z1,z1)) on the diagonal and the covariances symetrically in the upper and lower triangles.
I think to get the covarinace matrix, you need to create a vector of differences bewteen each point and the mean of all points, multiply it with it's transpose, then divide by the number of points.
So if z is a vector of random variables, C will be the covariance matrix
M = ones(1,length(z))*mean(z); % vector of mean values
Zc = z - M; % distances to the mean
C = (Zc'*Zc)./length(z); % covariance matrix
1 comentario
Kanike Sreekanth
el 15 de Abr. de 2021
if they are zero mean random variables, can we just perform "xcorr" to the matrix??
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!