Last value of Moving Average in single command

2 ビュー (過去 30 日間)
Inna Pelloso
Inna Pelloso 2022 年 6 月 29 日
コメント済み: Voss 2022 年 6 月 29 日
Hi,
I have A = rand(10,1). I am calculating an exponential moving average, B = movavg(A,'exponential',2). I only want the last value of B, i.e. C = B(end).
Is there any way to do this in a single command?
Thank you!
IP

採用された回答

Voss
Voss 2022 年 6 月 29 日
Here's a way:
A = rand(10,1);
% original, for reference:
B = movavg(A,'exponential',2);
C = B(end)
C = 0.8873
% single-line command:
C = subsref(movavg(A,'exponential',2),substruct('()',{numel(A)}))
C = 0.8873
  2 件のコメント
Inna Pelloso
Inna Pelloso 2022 年 6 月 29 日
Thank you for showing me the subsref command!
Voss
Voss 2022 年 6 月 29 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTimetables in Finance についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by