How to calculate local running total in a updating loop?

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by