How to Implement the moving average filter in time domain in MATLAB?
HINT (really an answer but not providing code so its a hint):
In your setup, a $M$-point moving average filter uses the average of the previous $M-1$ samples and the current sample to compute the current output. So for $n=5$, the output will be $\frac{1}{5}(x[1]+x[2]+x[3]+x[4]+x[5])$. In general, for $n=k$ the output of this $M$-point MA filter is:
$$ \frac{1}{M}\sum_{n=k-M+1}^kx[k]$$