# 条件を満たさない要素を保持して演算する

1 view (last 30 days)
H.O on 11 Jul 2022
Commented: H.O on 12 Jul 2022

A＝
12 -11
-11 12
8 -11
A>10　の要素にだけ10を加算し，A<=10　は何も演算しないBを出力したいです．
B＝
22 -11
-11 22
8 -11
Indexを使うとA<=10が削除されてしまいます．
どのようにするとよろしいでしょうか．

Atsushi Ueno on 11 Jul 2022
> Indexを使うとA<=10が削除されてしまいます
⇒こういう事ですよね。
A = [12 -11; -11 12; 8 -11]
A = 3×2
12 -11 -11 12 8 -11
idx = A > 10
idx = 3×2 logical array
1 0 0 1 0 0
B = A(idx) + 10
B = 2×1
22 22

B = A;
B(idx) = B(idx) + 10
B = 3×2
22 -11 -11 22 8 -11
H.O on 12 Jul 2022

Hernia Baby on 11 Jul 2022
Edited: Hernia Baby on 11 Jul 2022

A = [12 -11; -11 12; 8 -11]
A = 3×2
12 -11 -11 12 8 -11
idx = A > 10;
B = A + idx*10
B = 3×2
22 -11 -11 22 8 -11

Hiro Yoshino on 11 Jul 2022
これじゃダメですか?
A = [12 -11; -11 12; 8 -11]
A = 3×2
12 -11 -11 12 8 -11
idx = A>10
idx = 3×2 logical array
1 0 0 1 0 0
A(idx) = A(idx) + 10
A = 3×2
22 -11 -11 22 8 -11

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!