MATLAB: How to extract the function from a piecewise defined function in Matlab

symbolicSymbolic Math Toolbox

I'm using the new Matlab piecewise function https://www.mathworks.com/help/symbolic/piecewise.html introduced in the Symbolic Math Toolbox R2016b to define a function, and I'm trying to extract the function expression part from the whole piecewise variable. Specifically my code looks something like:
syms x;
y = piecewise(x>1,3*x^2,0);
I'd like to be able to extract just the
3*x^2
from y without the condition.
Any idea how to do that?

Best Answer

You can use children() to extract the subexpressions of a symbolic expression.