Correlation (cor) vs. Covariance (cov)

8 次查看(过去 30 天)
Newuser
Newuser 2011-5-1
Hi all,
does someone know why to compute a loop with the cor function takes way longer than doing it with the cov function?
I've the followin loop
covC = cell(szX(1),1);
CovM = zeros(szX(1),szX(2));
for n = ws1+1:szX(1)
covC{n} = cov(((logr(n-ws1:n,:))));
CovM(n,:)= (covC{n}(1,:));
end
the matrix is ca. (1580x32)... if u run the posted loop it takes just a few seconds. However If I want to compute the correlation (and substitute cov with cor) it takes about 5 minutes
corC = cell(szX(1),1);
CorM = zeros(szX(1),szX(2));
for n = ws1+1:szX(1)
corC{n} = corr(((logr(n-ws1:n,:))));
CorM(n,:)= (corC{n}(1,:));
end
. I want to do it also with a 3000x1200 matrix
can someone suggest me a quicker prodecure to achive my goal?
thaks for ur hepl
  2 个评论
Newuser
Newuser 2011-5-1
Problem solved by using corrcoef
Oleg Komarov
Oleg Komarov 2011-5-1
You can use the compiler to verify where are the bottlenecks in corr as compared to corrcoeff.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by