Suppose i have a 4X1 matrix like [a;b;c;d]. Now i want the output as [a;(a+b)/2;(a+b+c)/3;(a+b+c+d)/4].
How to do that?

1 commentaire

Jos (10584)
Jos (10584) le 8 Août 2019
Answered! Great minds, as well as mine, think alike ;-)

Connectez-vous pour commenter.

 Réponse acceptée

Plus de réponses (3)

Adam
Adam le 8 Août 2019

0 votes

cumsum( [a; b; c; d] ) ./ ( 1:4 )';
madhan ravi
madhan ravi le 8 Août 2019

0 votes

cumsum(matrix)./(1:numel(matrix)) % where matrix is a column vector
Jos (10584)
Jos (10584) le 8 Août 2019

0 votes

One easy option
A = [10 20 30 40]
B = cumsum(A) ./ (1:numel(A))

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by