please i want to calculate sum of E generated (i.e 1 to 5). i try it but the last E generated is showing as Etotal
조회 수: 3 (최근 30일)
이전 댓글 표시
xm=100; ym=100;
sink.x=0.5*xm; sink.y=0.5*ym;
n=5;
PL =20;
TX=4;
Efs=10;
for j=1:1:n
S(j).xd=rand(1,1)*xm;
S(j).yd=rand(1,1)*ym;
distance=sqrt((S(j).xd-sink.x)^2 + (S(j).yd-sink.y)^2);
E=PL*(TX+Efs*(sqrt(distance)^2));% this is a formula
Etotal=sum(E)
end
댓글 수: 0
채택된 답변
Friedrich
2013년 8월 12일
Hi,
without having a close look I guess the last line should be:
Etotal = Etotal + sum(E)
Also declare Etotal to be 0 before your for loop.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!