Selecting positive or negative terms of a symbolic vector
3 views (last 30 days)
Show older comments
Farid Salazar Wong
on 23 Jun 2015
Commented: Star Strider
on 24 Jun 2015
I have a symbolic vector say [a^2*b^3, 0, -a*b^2, b^2, -a^4*b]. I would like to obtain two vectors from this. One of them only selecting the entries that have a positive coefficient, in this case I would like to obtain [a^2*b^3, b^2]. The other containing the entries with negative coefficient: [-a*b^2, -a^4*b].
I tried extracting the coefficients and then using if statement to create a vector with the positive entries and similar for the negative.
Is there a more efficient way to do this?
0 Comments
Accepted Answer
Star Strider
on 23 Jun 2015
This works:
syms a b c
V = [a^2*b^3, 0, -a*b^2, b^2, -a^4*b];
Vs = sign(V);
Vgz = V(Vs>0)
Vlz = V(Vs<0)
Vgz =
[ a^2*b^3, b^2]
Vlz =
[ -a*b^2, -a^4*b]
4 Comments
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!