필터 지우기
필터 지우기

Calculation of a double sum

조회 수: 1 (최근 30일)
xenon99942
xenon99942 2018년 7월 19일
답변: Dimitris Kalogiros 2018년 7월 19일
Hey all!
i want to calculate the double sum over w_ij * v_((2+k*3)+i,(2+l*3)+j). The indices for i should run from -1 to 1 (so -1,0,1), same for j. The indices for k are from 0:893 and for l from 0:356. And w should be -8 if i=j=0, otherwhise it is w=1. i Tried:
for i = -1:1
for j = -1:1
if i == 0 & j==0
w = -8
else
w = 1
end
for k = 0:893
for l = 0:356
sum(w*v((2+k*3)+i,(2+l*3))+j)
end
end
end
end
% code
end
But the results were not as expected. Can you help me? Thanks!

채택된 답변

Dimitris Kalogiros
Dimitris Kalogiros 2018년 7월 19일
mySum=0;
for i = -1:1
for j = -1:1
if i == 0 & j==0
w = -8;
else
w = 1;
end
for k = 0:893
for l = 0:356
mySum=mySum+( w*v((2+k*3)+i,(2+l*3))+j );
end
end
end
end
disp(['mySum = ' num2str(mySum)]);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by