Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

need to optimise my code

조회 수: 1 (최근 30일)
t g
t g 2012년 6월 4일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello friends,
i am writing a matlab optimisation program. Following is the segment of my code. for large value of m and n, this segment is taking longer time to execute. I want to optimise this code. Is there any body can help me in optimising this segment of code?
for s=1:m
for i=1:n
for j=1:n
for k=1:n
for l=1:n
A = A + D(k,l) * C(i,j,t) * B(i,k,s) * B(j,l,s);
end
end
end
end
end
thanks in advance...:)
  댓글 수: 1
Teja Muppirala
Teja Muppirala 2012년 6월 4일
Where did you come up with this? Is this just a direct translation from C or Fortran or something? This is probably just some simple matrix operation, but you've got it all written out in loops. Just like you did here:
http://www.mathworks.com/matlabcentral/answers/38829-about-nested-for-loop

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 6월 4일
See nice Teja' solution:
A = sum(arrayfun(@(ii)sum(sum(C(:,:,ii).*(B(:,:,ii)*D*B(:,:,ii)'))),1:size(C,3)))
if t ->s

태그

Community Treasure Hunt

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

Start Hunting!

Translated by