Replacing values in a matrix based on values in another matrix

12 ビュー (過去 30 日間)
Filip Hansson
Filip Hansson 2022 年 8 月 15 日
コメント済み: Filip Hansson 2022 年 8 月 15 日
If I have a matrix with "1"s and "0"s (A) and other matrixes of the same size with other values (B,C,D, etc), is it possible to find the locations of the "1"s in A in B,C,D,etc and replace these values with a constant number while the other values in B,C,D, etc are uneffected?
Thanks in advanced!

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 8 月 15 日
Use logical indexing (see Ch 11 of MATLAB Onramp)
A = [0 1 1 0]
A = 1×4
0 1 1 0
B = rand(size(A))
B = 1×4
0.1915 0.9248 0.8352 0.2674
B(A==1) = 99
B = 1×4
0.1915 99.0000 99.0000 0.2674

その他の回答 (0 件)

カテゴリ

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