Filter löschen
Filter löschen

problem using if with two vectors

1 Ansicht (letzte 30 Tage)
Tristan
Tristan am 30 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 30 Okt. 2013
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]

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 30 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 30 Okt. 2013
C=B
idx=A<0
C(idx)=A(idx)

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by