条件を満たさない要素を保持して演算する
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
行列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 Kommentare
Akzeptierte Antwort
Atsushi Ueno
am 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
Weitere Antworten (2)
Hernia Baby
am 11 Jul. 2022
Bearbeitet: Hernia Baby
am 11 Jul. 2022
自分はindexに10をかける方法で提案しますね。
A = [12 -11; -11 12; 8 -11]
idx = A > 10;
B = A + idx*10
0 Kommentare
Hiro Yoshino
am 11 Jul. 2022
これじゃダメですか?
A = [12 -11; -11 12; 8 -11]
idx = A>10
A(idx) = A(idx) + 10
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!