Correlation (cor) vs. Covariance (cov)

5 ビュー (過去 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 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by