Summing the row of a matrix that meet a condition from another matrix

1 回表示 (過去 30 日間)
Yaser Khojah
Yaser Khojah 2020 年 3 月 12 日
コメント済み: Yaser Khojah 2020 年 3 月 12 日
I need help please and thanks for looking into this
I have two Matrixes with the same size as A and B. As the following
A = [1, 0, 0; 0, 0, 3; 1, 0, 0];
B = [2, 4, 5; 4, 3, 1; 4, 6, 1];
I would like the sum the columns in B for every row only for the same index in A that has zero. This should be done for every row to get:
C = [9; 7; 8]

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 12 日
C = sum(B.*(A==0), 2);

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by