フィルターのクリア

problem using if with two vectors

2 ビュー (過去 30 日間)
Tristan
Tristan 2013 年 10 月 30 日
編集済み: Azzi Abdelmalek 2013 年 10 月 30 日
for example if I have :
>> A=[1 -2 -8 4 19 -6 7 -18 9];
>> B=[-16 1 2 -4 -19 6 -17 18 -9];
and I'd like to create a new vector C which is equal to A if A<0 otherwise it should return B instead, like this:
C=[-16 -2 -8 -4 -19 -6 -17 -18 -9]

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 30 日
編集済み: Azzi Abdelmalek 2013 年 10 月 30 日
C=B
idx=A<0
C(idx)=A(idx)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by