problem using if with two vectors

조회 수: 1 (최근 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 CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by