How do I extract the function from a piecewise defined function in Matlab?

237 views Asked by At

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. 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?

1

There are 1 answers

0
Mendi Barel On BEST ANSWER

Use children:

syms x;
y = piecewise(x>1,3*x^2,0);
childs=children(y)
myfunc=childs(1)