selecting from a list

Dan Nigrin's icon

I have a list - say for example [50 53 57 58].

I now have another list, composed of only zeros and ones, and of the exact same length as the list above. Say for example [1 0 1 1].

I'd like to generate a 3rd list, that represents only the elements of the 1st list, for which there is a corresponding "1" in the same position in the 2nd list. In our example, the resulting 3rd list would be [50 57 58].

Is there a clean, easy way to do this? I can brute force it using various zl objects, but thinking there must be some sexy way.... ;-)

Roman Thilenius's icon


you mean... with 3 or less objects? hmm...

LSka's icon

with 2 objects!

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

pdelges's icon

But what should happen if the lists are [50 0 57 58] & [0 1 0 0] ? ;-)

Source Audio's icon

this can probably be done in more efficient way

just a first thought I had

Roman Thilenius's icon


i have an abstraction for that which consists of 10 objects (including the IO)

it starts with vexpr like @LSKA above - but something like zl filter does not exist for my version of max, so changin the length is a pita. :)

also note that this type of solution wont work if there are zeros in the right list.

Dan Nigrin's icon

Thanks for all the replies!

@LSKA - your method is beautiful and works perfectly for my needs, as my first list will never have a zero in it. And even better, I'm embarrassed to say that in all my years of Max'ing I've never used or known of the vexpr object - it's exactly what I was thinking of in my head, "how can I multiply each element of the lists together?" - and boom, there it is. Thank you!