条件を満たさない要素を保持して演算する
1 view (last 30 days)
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が削除されてしまいます.
どのようにするとよろしいでしょうか.
0 Comments
Accepted Answer
Atsushi Ueno
on 11 Jul 2022
> Indexを使うとA<=10が削除されてしまいます
⇒こういう事ですよね。
A = [12 -11; -11 12; 8 -11]
idx = A > 10
B = A(idx) + 10
下記のように使えば、条件を満たさない要素は保持されます。
B = A;
B(idx) = B(idx) + 10
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
0 Comments
Hiro Yoshino
on 11 Jul 2022
これじゃダメですか?
A = [12 -11; -11 12; 8 -11]
idx = A>10
A(idx) = A(idx) + 10
0 Comments
See Also
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!