So I've been writing a code in matlab designating certain values as symbols, for example

sym = S, S1S, x, y

S = ax + by + c..

S1S = S^2..

So I get an output for S1S of the form a^2x + 2abyx + b^2y^2.... ect..

What I want to do know is find a way of taking the co-efficients of the variables, so I can perform operations like dividing a chosen variable into the equation S1S. Any ideas?

And just to clarify, it may seem that it's easy to do because a, b and c are specified, but in my actual code, these values are calculated from a more complicated manipulation and as such I have no general form for them, so I just need a method to extract the chosen co-efficients and use them independently. Any idea? Thanks!