How to calculate local running total in a updating loop?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!