MATLAB: Moving sum using movsum()

arraydiscardendpointcalculationsendpointsMATLABmovingsum

I am new to matlab and this is a code for computing moving sum from 3 consecutive numbers in matlab from Mathworks documentation. I am unable to understand what they mean by discarding endpoint calculations in the explanation(underlined ). I do not understand the significance of endpoints and discard keyword in the given documentation.If someone can explain this it would be very helpful .
Compute the three-point centered moving sum of a row vector, but discard any calculation that uses fewer than three points from the output. In other words, return only the sums computed from a full three-element window, discarding endpoint calculations.
A = [4 8 6 -1 -2 -3 -1 3 4 5];
M = movsum(A,3,'Endpoints','discard')
M = 1×8
18 13 3 -6 -6 -1 6 12

Best Answer

If you do not specify the endpoints to be discarded, the MATLAB appends zeros at both ends of the array to make them the window fit. For example, if you run
A = [4 8 6 -1 -2 -3 -1 3 4 5];
M = movsum(A,3)
then MATLAB will create matric A like this
A = [0 4 8 6 -1 -2 -3 -1 3 4 5 0];
so that window of size 3 can fit at 4 (first element) and 5 (last element)