problem using if with two vectors

2 次查看(过去 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