Hi Angel,
The "movmean" function calculates and returns an array of mean values, with each mean computed over a sliding window of specified length, "windowsize." The position of the sliding window is determined by the current element for which the mean is being calculated and the provided "windowsize."
In the first scenario, the "windowsize" provided is an even number. Therefore, the sliding window positions its center between the "current" element and the element before the "current" element.
To calculate the mean for first element in the array, the sliding window position would be as follows:
[4 8 6 -1 -2 -3 -1 3 4 5];
As there is only one element in the sliding window the mean value would be
In the second sceanrio, the "windowsize" provided is odd. Therefore, the sliding window positions its center at the current value. The position of sliding window for the first element in the array would be as follows:
[4 8 6 -1 -2 -3 -1 3 4 5];
There are 2 elements in sliding window, the mean value would be
And the third scenario is similar to the first scenario. The sliding window with "windowsize" of value 4 would be positioned as follows:
For the first element
[4 8 6 -1 -2 -3 -1 3 4 5];
The mean would be:
For the second element
[4 8 6 -1 -2 -3 -1 3 4 5];
The mean would be:
To learn more about the "movmean" function, please refer to the following documentation:
I hope this clarifies how the "movmean" function performs the "moving mean".