Filter out from a list all numbers bigger / smaller than a certain value.

Rugerfred_84's icon

Hi. Is it possible to filter out from a list all negative / all positive numbers?

And is it possible to remove all numbers bigger or smaller than a certain changeable value?

Christopher Dobrian's icon

To remove a specific (relatively small) set of numbers from a list, I suggest you use [zl filter].

To remove a range of numbers (such as all negative numbers) from a list, one method is to convert the list into a stream of individual numbers with [iter], filter those numbers with [split] or [if], then reconcatenate them as a list with [thresh]. (See the caveat in this example.)

Max Patch
Copy patch and select New From Clipboard in Max.

Rugerfred_84's icon

Cool! Exactly what I was looking for. Thank you very much!

Roman Thilenius's icon

vexpr ($f1<=5.) * -777777

/

t -7777777 l

/ /

zl union

/

zl slice 1 (second outlet)

/

Roman Thilenius's icon
Roman Thilenius's icon

placeholders can save you from unpacking lists

Christopher Dobrian's icon

Roman, you had the right idea, but your formula was wrong (and of course this method rules out any input that matches the 'placeholder').

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

thanks for correction (you can tell i did that without max)

but no, i dont think -777777 will ever be greater than 5? or am i too tired now.

Christopher Dobrian's icon

You're right about that. As long as one uses as a placeholder a number that will be filtered out anyway by the condition, it'll be okay.