필터 지우기
필터 지우기

For loop with previous result

조회 수: 1 (최근 30일)
Jane Smith
Jane Smith 2021년 3월 5일
댓글: Jane Smith 2021년 3월 5일
for t=1:n
a(t)=600+10^t
b(t)=600-a(t)
end
I want that b to always taking the previous result
so, b(1)=600-a(1)
b(2)=(600-a(1))-a(2)
b(3)=(600-a(1)-a(2))-a(3)
how can i change the t

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 3월 5일
hello Jane
this is it :
at the k step : b(k) is 600 - sum of a from 1 to k
for t=1:n
a(t)=600+10^t;
b(t)=600-sum(a(1:t));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by