Cumulative Mean of a Matrix

9 views (last 30 days)
Ashley
Ashley on 1 Nov 2012
Hi,
I have a matrix: Vx=[4,5,6,3,2,4,5,6,4,3,2,5,6,7,5] etc.
I want to find the cumulative mean of these values (to see if the velocity field converges with time).
Does anyone have a good method to do this?
I have
for k=1:1:15;
CumuVel=mean(Vx(1,1):Vx(1,k));
end
But this won't work....any suggestions?
Thanks
  3 Comments
Teja Muppirala
Teja Muppirala on 2 Nov 2012
I agree with Image Analyst, to see if something is converging, it is not sufficient to just look at the cumulative mean.
For example, this series Vx is diverging, but the cumulative mean still converges:
Vx = sqrt(1:1000) .* (-1).^(1:1000)
plot(Vx); % Clearly not converging
CumuVel = cumsum(Vx)./(1:length(Vx)); % Get cumulative mean
figure, plot(CumuVel); % Vx is diverging, this is converging
Jan
Jan on 2 Nov 2012
I assume, you mean:
CumuVel = zeros(1, 15); % Pre-allocation!!!
for k = 1:15;
CumuVel(k) = mean(Vx(1:k));
end

Sign in to comment.

Answers (1)

Matt J
Matt J on 1 Nov 2012
CumuVel = cumsum(Vx)./(1:length(Vx));
  2 Comments
Jan
Jan on 2 Nov 2012
@Matt J: 6 Votes in 17 hours!
Matt J
Matt J on 2 Nov 2012
Edited: Matt J on 2 Nov 2012
It's pretty bizarre. No idea why such a simple Answer to such a simple Question is attracting so much attention.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!