Last value of Moving Average in single command

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timetables in Finance 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by