条件を満たさない要素を保持して演算する
Show older comments
行列Aがあるとします.
A=
12 -11
-11 12
8 -11
A>10 の要素にだけ10を加算し,A<=10 は何も演算しないBを出力したいです.
B=
22 -11
-11 22
8 -11
Indexを使うとA<=10が削除されてしまいます.
どのようにするとよろしいでしょうか.
Accepted Answer
More Answers (2)
Hernia Baby
on 11 Jul 2022
Edited: Hernia Baby
on 11 Jul 2022
自分はindexに10をかける方法で提案しますね。
A = [12 -11; -11 12; 8 -11]
idx = A > 10;
B = A + idx*10
これじゃダメですか?
A = [12 -11; -11 12; 8 -11]
idx = A>10
A(idx) = A(idx) + 10
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!