MATLAB: Selecting positive or negative terms of a symbolic vector

symbolic

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?

Best Answer

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]