What you are describing is known as a moving average filter.
If you want to do this in simulink (i.e. while running the simulation), you could implement it as a filter. You can create it with blocks, but for a window of 40 samples, that would be a pain. I would thus suggest to either use an S function block, or define the filter coefficients
N = 40;
b = ones(1,N)/N;
a = 1
and use a transfer function block. There is also a Simulink tutorial on how to create an actual simulink "object" for a moving average filter, see here
If you want to do this as post-processing in Matlab, there are plenty of ways to do this. One possibility is to view it as a convolution, i.e.
N = 40;
t = linspace(0,2,100);
x_raw = sin(2*pi*t) + randn(1,length(t));
mav_filt = ones(1,N)/N;
x_mav = conv(x_raw,mav_filt,'same');