MATLAB Answers

Separate the positive values from the negative values

28 views (last 30 days)
abdullah qasim
abdullah qasim on 11 Jan 2019
Edited: madhan ravi on 11 Jan 2019
I have the following
X=[1 - 3 5 -8 4 9 -6 -3]
I want to separate the polarity ( positive values from the negative values) like this
Xp=[1 5 4 9]
Xn=[-3 -8 -6 -3]
then flip the negative values to positive values
like
Xn=[3 8 6 3]
then pass the values as a two-step
like
first, pass the positive step and the second pass the negative steps
NOTE : general methods

  0 Comments

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 11 Jan 2019
Edited: madhan ravi on 11 Jan 2019
Xp=X(X>0)
Xn=X(X<0)
Xn=abs(Xn)

  4 Comments

Show 1 older comment
madhan ravi
madhan ravi on 11 Jan 2019
Xn=-Xn
Note : Only works if all the numbers are less than 0.
Xn(Xn<0)=-Xn(Xn<0) % alternate would work generally

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by