Averaging rows with rows previous

1 view (last 30 days)
WBOZ11
WBOZ11 on 21 Feb 2018
Commented: WBOZ11 on 22 Feb 2018
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?

Accepted Answer

James Tursa
James Tursa on 21 Feb 2018
Edited: James Tursa on 21 Feb 2018
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))');

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!