MATLAB: How to get the coefficients of this symbolic expression

extract coefficients symbolicSymbolic Math Toolbox

This is the symbolic expression:
(4525*Kd*s^2 + 4525*Kp*s + 4525*Ki)
--------------------------------------------------------
(1843*s^3 + (4525*Kd + 31575)*s^2 + 4525*Kp*s + 4525*Ki)
The result I need is just the coefficients of s in the denominator
1843
(4525*Kd + 31575)
4525*Kp
4525*Ki
Is there one easy way to do it or do I need to put it all in a string and do a lot of string manipulations?
PS: All letters in the expression are symbolic, sym2poly doesn't work in that case

Best Answer

coeffs(denom(Expression),s)
You will want to use the two-output version of coeffs(), as coeffs does not insert coefficients of 0 for absent powers.