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에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!