Average of matrix element
显示 更早的评论
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 个评论
Jos (10584)
2019-8-8
Answered! Great minds, as well as mine, think alike ;-)
采纳的回答
更多回答(3 个)
Adam
2019-8-8
cumsum( [a; b; c; d] ) ./ ( 1:4 )';
madhan ravi
2019-8-8
cumsum(matrix)./(1:numel(matrix)) % where matrix is a column vector
Jos (10584)
2019-8-8
One easy option
A = [10 20 30 40]
B = cumsum(A) ./ (1:numel(A))
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!