How to calculate local running total in a updating loop?

조회 수: 4 (최근 30일)
Hao Zhang
Hao Zhang 2020년 2월 18일
댓글: Hao Zhang 2020년 2월 19일
I have a variable A in a time updating loop, A is updated by a functoin f to another value:
While t<=T
A=A+f(B);
end
Now, Compute the running total of A is very simple:
S=0;
While t<=T
A=A+f(B);
S=S+A;
end
However, I only want the 10 most recent values of A to be added up in S:
S(t)=A(t-9)+A(t-8)+A(t-7)+A(t-6)+A(t-5)+A(t-4)+A(t-3)+A(t-2)+A(t-1)+A(t);
How could I do this in the loop? Note that it is not practical to save all the histroy of A into the memory because A is extremely big, not even the 10 most recent values. What is the most memory efficient way to do this?
Thanks!

답변 (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