plot mean of vector v(1:i)

조회 수: 2 (최근 30일)
Thales
Thales 2018년 12월 11일
편집: Stephen23 2018년 12월 11일
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?

채택된 답변

Stephen23
Stephen23 2018년 12월 11일
편집: Stephen23 2018년 12월 11일
plot(v,cumsum(v)./(1:numel(v)))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by