Converting positives to negatives in a column.

조회 수: 29 (최근 30일)
Christopher
Christopher 2013년 9월 8일
I have somewhat of a confusing problem that I need help with. I am going to explain it the best that I can, so here goes. I have two column vectors, one is Cp the others is Cf. The Cp column has positive values and some negative values. I basically need to take the rows in the Cp column that are negative and make the same rows of Cf negative. For example:
Cp=[1;2;-3;-4;5]
Cf=[1;3;5;7;9]
Then the new column vector would be:
new_vector=[1;3-5;-7;9]
Basically making any negative row in Cp, negative in Cf.
Is there any easy way to do this? Any help is much appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 8일
Cf(Cp<0) = -Cf(Cp<0);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by