Is this code for doing a moving average correct?
Yes, this code is correct for implementing a moving average filter. 

Nevertheless I do recommend to use the in-built smooth function in MATLAB.

y = smooth(x, 100, 'moving')