matrix comparison and substitute value

2 ビュー (過去 30 日間)
Nafila Farheen
Nafila Farheen 2019 年 11 月 6 日
回答済み: Walter Roberson 2019 年 11 月 6 日
Hi, I have one matrix
A=[4 2 3
9 5 6]
I have another vector b=[1 0]. I want to compare the first column of A with b, and if the position in A correspondes to a 1 in b, then I would like to replace that value (4 multiply 0.99) and if 0, it will keep as it is . I was wondering is there any way to do that without executing nested for loops?TIA

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 11 月 6 日
A = A * (1 - 0.01 * (repmat(b.', 1, size(A,2)) == 1))

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by