MATLAB: How can i do the rolling sum of the elements of a vector

rolling sum

Hello everyone,
I would like to compute the rolling sum i a vector. i make an example:
A(10×1)=[1 2 3 4 5 6 7 8 9 10]
In my case i would like to obtain
B(8×1)=[6 9 12 15 18 21 24 27],
so taking a rolling window of 3 numbers, condidering ONLY the last three numbers

Best Answer

Hi,
if you use R2016a or later try movsum. For your example see especially this section:
Best regards
Stephan
Related Question