フィルターのクリア

How do I add to specific parts of an array?

8 ビュー (過去 30 日間)
Thomas Hoyle
Thomas Hoyle 2016 年 12 月 13 日
コメント済み: Thomas Hoyle 2016 年 12 月 13 日
Say for example I have A = 5 2 7 4 1 6 3 8 B = 4 7 2 5 8 3 6 1
How would I go about adding B to only values in A that are above 4? so the result is C = 9 2 9 4 1 9 3 9 I know I can use A(A>4) this will give me all values above 5 but I don't know how to add B to those specific values. Just to be clear I don't want to add the lines this is just a simple example the one I am working on is 4000x4000 with the values are more random and have no simple order to them.

採用された回答

KSSV
KSSV 2016 年 12 月 13 日
編集済み: KSSV 2016 年 12 月 13 日
A = [5 2 7 4 1 6 3 8 ] ;
B = [4 7 2 5 8 3 6 1];
iwant = A ;
iwant(A>4) = A(A>4)+B(A>4)
  1 件のコメント
Thomas Hoyle
Thomas Hoyle 2016 年 12 月 13 日
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by