4D matrix multiplication

조회 수: 6 (최근 30일)
Kamran
Kamran 2021년 10월 15일
댓글: Kamran 2021년 10월 20일
I do the following in 4 loops and it takes ages to complete. Is there a way this code could be made more efficeint, without using parallel processing toolbox?
'steer' is a 136x101x101x16 matrix
'R' is a 136x16x16 matrix
'pow' and 'F' are 101x101 matrices.
pow = zeros(grdpts_y, grdpts_x); %grdpts_y, grdpts_x = 101
for l=1:nf %nf = 136
F = zeros(grdpts_y,grdpts_x);
for i=1:grdpts_x
for j=1:grdpts_y
F(i,j) = F(i,j) + 1./(squeeze(steer(l,i,j,:))'*squeeze(R(l,:,:))*squeeze(steer(l,i,j,:)));
end
end
F = F.*conj(F);
pow = pow + F;
end
Thanks in advance,
Kamran

채택된 답변

Matt J
Matt J 2021년 10월 15일
편집: Matt J 2021년 10월 18일
steer=reshape( permute(steer,[2,3,4,1]),101^2,[],136 );
R=permute(R,[2,3,1]);
F=1./sum( pagemtimes(conj(steer),R).*steer, 2);
F=reshape( abs(F).^2 ,101,101,[]);
pow=sum(F,3);
  댓글 수: 10
Matt J
Matt J 2021년 10월 19일
편집: Matt J 2021년 10월 19일
In your new version, F will always be real, non-negative, so I don't know why you would still be computing conj(F).
steer=reshape( permute(steer,[2,3,4,1]),101^2,[],136 );
Vec_n=cell(1,nf);
for l=1:nf
[Vec, Val] = eig(squeeze(R(l,:,:)));
[Val Seq] = sort(max(Val));
Vec_s = Vec(:,Seq(nstat ,nstat));
Vec_n{l}= Vec(:,Seq(1:nstat-1));
end
Vec_n=cat(3,Vec_n{:});
F=1./sum( abs(pagemtimes(conj(steer),Vec_n)).^2, 2);
F=reshape( abs(F).^2 ,101,101,[]);
pow=sum(F,3);
Kamran
Kamran 2021년 10월 20일
Thank you very much. You are of course right. Thanks again for the prompt help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by