Working with piecewise answer in MATLAB

87 Views Asked by At

Sometimes MatLab gives me answer in piecewise notation, like this:

piecewise([1 < x, 0], [abs(x) < 1, -(log(x - 1) - 1)*(x - 1)])

Is it possible to take any pair from answer?

For example, take second pair from previous answer (will be -(log(x - 1) - 1)*(x - 1)).

P.S. I using Symbolic Toolbox in this case.

1

There are 1 best solutions below

0
On

From the online MATLAB R2014b documentation :

Access Methods

...

expression — Object in a specific branch

expression(p, i)

Instead of piecewise::expression(p, i), the index operator p[i] can be used synonymously.

In your example, p would be your original answer, and i would be 2. You can also access the condition of a branch using condition(p, i), the whole branch by branch(p, i), or the number of branches by numberOfBranches(p).