Generating covariance from matrix
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ryan Chow
le 24 Jan 2020
Commenté : Walter Roberson
le 24 Jan 2020
I have the data y as follows and I am trying to find the covariance between the 1st row and 2nd row, 2nd row and 3rd row, 3rd row and 4th row, so on. I don't seem to be able to save the values into a matrix either and would appreciate any hints. Thank you!
y = rand(20,1)
for i = 1:20
autocov=cov(y(i:19),y(i+1:20))
end
0 commentaires
Réponse acceptée
Walter Roberson
le 24 Jan 2020
Modifié(e) : Walter Roberson
le 24 Jan 2020
N = 20;
y = rand(N,1);
autocov = zeros(2, 2, N);
for i = 1:N
autocov(:, :, i) = cov(y(i:19),y(i+1:20));
end
The result will be a 2 x 2 x 20 array.
2 commentaires
Walter Roberson
le 24 Jan 2020
N = 20;
y = rand(N,1);
cov12 = zeros(1,N);
for i = 1:N
autocov = cov(y(i:19),y(i+1:20));
cov12(i) = autocov(1,2);
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!