フィルターのクリア

Average of matrix element

2 ビュー (過去 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 Center および File ExchangeSignal Attributes and Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by