ZL Filter question

keepsound's icon

I have a strange issue with zl filter, or maybe I can't understand it completely, also because this issue is present just in the version 6, then in the 7 and now in all the 8 versions... What I can't' understand, is the list coming out from the right oulet from the object (see the attached picture)... Example: my list is "a b c d e f g", and I need to remove the "a" and the "e", [zl filter a e], that means the 1st and the 5th item of the list. From the left outlet the outcoming list is correct, but the outcoming list from the right outlet should be "1 5" (or "0 4" if the list use the 0 == 1) ...but isn't. Anyone can explain me better this issue? Best regards, Italo

...

Andy Maskell's icon

I think you have misunderstood a couple things.

In Max, indexes always start at 0 (zero), not 1. Think of them as more like an offset from the beginning rather than the number in the list. That’s how computer memory indexing works. The first item in the list is zero from the beginning, the second is one from the beginning, etc.

Secondly, [zl.filter] removes items from a list so what comes out is what you have left after the specified items have been removed (filtered out). The left hand outlet gives the remaining list items and the right hand outlet gives you the indexes for where those items were in the original list.

Don’t forget, in your examples, “a” is the first item in the list so it has an index (offset) of zero. “e”, being the fifth item in the list has an index (offset) of 4 not 5. So in you second example, the items that have been removed (a & e) are indices 0 & 4.

keepsound's icon

It's simply reversed - And it's to add a [vexpr $i1 + 1] obj
thx

Roman Thilenius's icon


i dont understand the picture. why should only 5 be left when you remove 1 from 7?

Andy Maskell's icon

I think he though only index 5 should remain, not 5 indices.

Jean-Francois Charles's icon

A solution among others:

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

keepsound's icon

Solved

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

keepsound's icon

Limited to 10 items ...but can be dynamic with a JS. I added a "none" if the list and the searched ID are not correct, and the objs helps. Added a set-loadbang too, for the initialization. The subpatch can also work alone (aka without the "zl filter"). The out is 1 based (can be 0 based with a obj [vexpr $i1 -1]).

keepsound's icon

Accept numbers (int or floats), letters or lists (also combined)