フィルターのクリア

Is it possible to get rid of the for loop in the following code?

1 回表示 (過去 30 日間)
Iremsu Savas
Iremsu Savas 2018 年 10 月 6 日
コメント済み: Iremsu Savas 2018 年 10 月 6 日
I have a matrix A(52,4) with some values in it and I have another matrix B(52,1) with 1's and 0's in it. I want to control the B matrix and if the B matrix's value is 1 in the following index then I want to make the A matrix's that index full of zeros.With for loop I can do it as it follows but is it possible in matlab to make it in another way and get rid of this for loop?
for a=1:52
if B(a,1)==1
A(a,:)=0
end
end
thank you

採用された回答

Walter Roberson
Walter Roberson 2018 年 10 月 6 日
A(B(:, 1)==1,:) = 0;
Or
A(logical(B), :) = 0;
If you were to maintain B as logical instead of numeric then just
A(B, :) = 0;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by