MATLAB: Averaging rows with rows previous

averagedata

I have data in a matrix where I need each consecutive row to be the average of all the rows above this. How would I go about this?

Best Answer

Assuming the average includes the row in question:
x = your matrix
result = cumsum(x)./(1:size(x,1))';
Or for earlier versions of MATLAB:
result = bsxfun(@rdivide,cumsum(x),(1:size(x,1))');