How to calculate local running total in a updating loop?

3 vues (au cours des 30 derniers jours)
Hao Zhang
Hao Zhang le 18 Fév 2020
Commenté : Hao Zhang le 19 Fév 2020
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!

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by