How to calculate local running total in a updating loop?

2 次查看(过去 30 天)
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