Correlation (cor) vs. Covariance (cov)
3 views (last 30 days)
Show older comments
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 Comments
Oleg Komarov
on 1 May 2011
You can use the compiler to verify where are the bottlenecks in corr as compared to corrcoeff.
Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!