Average of matrix element

조회 수: 4 (최근 30일)
Supriya Gain
Supriya Gain 2019년 8월 8일
댓글: Jos (10584) 2019년 8월 8일
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)
Jos (10584) 2019년 8월 8일
Answered! Great minds, as well as mine, think alike ;-)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 8일
x = [a;b;c;d];
cumsum(x) ./ (1:numel(x))

추가 답변 (3개)

Adam
Adam 2019년 8월 8일
cumsum( [a; b; c; d] ) ./ ( 1:4 )';

madhan ravi
madhan ravi 2019년 8월 8일
cumsum(matrix)./(1:numel(matrix)) % where matrix is a column vector

Jos (10584)
Jos (10584) 2019년 8월 8일
One easy option
A = [10 20 30 40]
B = cumsum(A) ./ (1:numel(A))

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by