# Question:how to filter out undefined result from piecewise output

## Question:how to filter out undefined result from piecewise output

Maple 2018

After solving something, sometimes the result comes in piecwise. I'd like to just obtain all those results which are not undefined, into a list, so I can process them more easily. I am not sure what is the correct way to do this in Maple.

Here is an example.

```restart;
f := piecewise(x>-1 and x<=0, x^3,
x>0 and x<=Pi/2, sin(x),
x>Pi/2, undefined,
x=20, 5,
x=50, undefined);
```

I need to pick all entries that do not have "undefined". I do not need the rhs condition  which is x<=1. So for the above, I'd like to obtain

sol:=[ x^3, sin(x), 5]

If there more entries which are also not undefined, they go into the list in order.

when I do

`sol:=convert(sol,pwlist,x);`

This gives

```sol := [0,-1,x^3,0,sin(x), (1/2)*Pi,undefined,20,undefined,20,undefined,50,undefined,50,undefined]
```

Now it gets confusing. How to change the above to

sol:=[ x^3, sin(x), 5]

I do not even understand the conversion result above. I do not know why it gives 50 twice. And I do not even see the "5" in there. So I do not know how to decode this now.

Update:

I found this solution. But it might not be best:

```contents :=[op(f)];
[seq(`if`(contents[i]=undefined,NULL,contents[i]),i=2..nops(contents),2)];
```

gives

[x^3, sin(x), 5]

﻿