Hello,
I have two matrices of equal size. One contains negatives and the other does not. I want top convert the values on the positive matrix, that correspond top the negative valus on the other matrix, to negatives. i.e., if: A = [2,1,0,-1,-2,-1,0,1,2]; and B = [4,2,0,2,4,2,0,2,4];
what is the easiest way to make:
B = [4,2,0,-2,-4,-2,0,2,4];
Thanks,
Max

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 7월 5일
편집: Andrei Bobrov 2017년 7월 5일

0 개 추천

B.*sign(A)
or
(1-(A < 0)*2).*B
or
B(A < 0) = -B(A < 0);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2017년 7월 5일

댓글:

2017년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by