MATLAB: Plot mean of vector v(1:i)

meanplotplotting

For simplicity, I have the following code
v=1:10;
for i=1:10
mean_v(i) = mean(v(1:i));
end
plot(v,mean_v)
In essence, I want to plot the mean of the vector from elements 1 to i, as a function of the i-index. Any way I could do it in one line?
plot(v,mean(v(1:?)))
What should I change in the mean(v(1:?)) part?

Best Answer

plot(v,cumsum(v)./(1:numel(v)))