Alternative for unefficient code using corrcoef in a for-loop

2 ビュー (過去 30 日間)
Florian
Florian 2012 年 3 月 14 日
Dear specialists, I have the following problem. The matrix G is a cross-realization cross-correlation matrix. It is calculated from correlation coefficients of large (~200,000 dimensional) vectors. G is symmetric, which is being accounted for by the if-loop. The following code seems to be very inefficient, as I know that for-loops are normally not the best method in MATLAB. However, I could not come up with an idea how to make it more efficient, so far. Maybe, one of you can give me a hint.
Best regards
Florian
G=zeros(nc*K);
for l=1:K
for m=1:K
if l<=m
for i=1:nc
for j=1:nc
[R,P]=corrcoef(x(l,i,:),x(m,j,:));
G((l-1)*nc+i,(m-1)*nc+j)=R(1,2);
end
end
else
G((l-1)*nc+1:l*nc,(m-1)*nc+1:m*nc)=G((m-1)*nc+1:m*nc,(l-1)*nc+1:l*nc)';
end
end
end
Definition of x:
for i=1:nc
x(l,i,:)=double(reshape(nii.img(:,:,:,i),s,1));
end
where nii.img are three-dimensional images loaded in an earlier step. s here is ~ 200,000. K and nc are ~50.

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by