フィルターのクリア

how to find average value up to current row in Matrix

2 ビュー (過去 30 日間)
Triveni
Triveni 2022 年 11 月 26 日
コメント済み: Triveni 2022 年 11 月 26 日
I have a matrix A
A =
[ 128 8.4
127 8.7
128 8.3 ]
I want to find average using A(1,1) * A(1,2)/sum(A(1,1)) for first row. And subsequently for next rows considering calculation of previous row.. And I need the values
B = [
128 8.4
255 8.549
383 8.466 ]
Please help me.

採用された回答

Bruno Luong
Bruno Luong 2022 年 11 月 26 日
A = [ 128 8.4
127 8.7
128 8.3 ]
A = 3×2
128.0000 8.4000 127.0000 8.7000 128.0000 8.3000
A1 = A(:,1);
cs1 = cumsum(A1);
B = [cs1, cumsum(A1.*A(:,2))./cs1]
B = 3×2
128.0000 8.4000 255.0000 8.5494 383.0000 8.4661
  1 件のコメント
Triveni
Triveni 2022 年 11 月 26 日
B = [cumsum(A(:,1)), cumsum(A(:,1).*A(:,2))./cumsum(A(:,1))]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by