MATLAB Answers

How to calculate moving covariance in a matrix?

26 views (last 30 days)
Hi guys, Hi Guys, I have got a matrix :378x9. I need to calculate the moving covariance with a window size of 120(starting from row one). Can somebody help me please? Thank you very much Andrea
Andrea Finocchiaro
Andrea Finocchiaro on 9 Oct 2015
Yes,correct that is the moving window I mena. But why correlation?I am looking for the Covarinces

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 9 Oct 2015
% Generate some pretend data. Use your real data here.
data = rand(378,9);
[M,N] = size(data);
window = 120;
numberCovarianceMatrices = M - window + 1;
covarianceMatrices = zeros(N,N,numberCovarianceMatrices);
for nc = 1:numberCovarianceMatrices
covarianceMatrices(:,:,nc) = cov(data(nc:(nc+window-1),:));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by