Substitute single number in a list

Nick Dulworth's icon

I am trying to figure out how to substitute a single number in a defined list. For example, you start with a list of 200 zeros. You also have an index of a specific zero within that list and the number you want to replace it with. In addition, each time you replace a single zero with a number, everything else in the list must return to zero.

I have found out a way to do this with route, but it is very inefficient and I was hoping that there was a better way.

Nick Dulworth's icon

I have created this patch as an example of what I am trying to accomplish. This does what I want, I was just hoping there was a more efficient way to achieve the same goal

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

double_UG's icon

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

Source Audio's icon

With very long lists I would use coll.

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

double_UG's icon

or Multislider

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

Roman Thilenius's icon


1. set incoming list to pak
2. set changes to individual elements to pak (using a [gate 255] or similar lego tech)
3. trigger result from pak

(using pak only works when data type is known and length is fixed)

Diemo Schwarz's icon

The only sane workaround making up for Max's lack of a proper list storage/manipulation object is the super-hidden 2nd inlet feature of [zl mth/nth]:

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

jg's icon

Here's a flexible way of doing it using one of Max's sane storage/manipulation objects ;-) (just send appropriate size messages to [table] and [group])

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

Diemo Schwarz's icon

@JG: copy/paste error? Your patch is the same as above....

jg's icon

Whoops! Thanks, Diemo. Here's the right one:

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

Pedro Santos's icon

One more vote for zl.rot!

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

Diemo Schwarz's icon

If you can live with lists of size >= 2, containing only integers, and some extra patching to get the whole list then, sure, you could call [table] sane (at least relative to the thicket Max has organically grown into during the last 30 years =-)

jg's icon

@diemo - isn't a list < 2 just a number? :-) I take the point re. integers; I guess you could do some trickery with multiplying before the table and dividing after it, but that's a bit fussy. You could also use [capture], tho' that again is fussier than [table].
@Pedro - that trick with [zl.rot] is very nice!of size

And agreed, Max has become quite a thicket - I often wonder if it couldn't be tidied up a bit. Re. the extra patching after [table]: I don't see it as extra - given one's use case, you may want the numbers out of table as a list or as a series of separate numbers; the system is flexible, hence a bit more complicated.

Diemo Schwarz's icon

isn't a list < 2 just a number?

No, it isn't.

It is a list of length 1, or of length zero, the latter being something that is impossible to represent concisely in Max, without setting flags and handling special cases all the way through. (See this discussion https://www.facebook.com/groups/maxmspjitter/permalink/10159143189409392/)

And agreed, Max has become quite a thicket - I often wonder if it couldn't be tidied up a bit.

That thicket grows its roots in backwards compatibility, which is something we all cherish and depend upon... (Cycling is doing a great job in this respect, shielding us from the upgrade hell of OSes, apps and frameworks.)

One way out of the thicket is to use a proper programming language, like JavaScript, another to use well-crafted packages for sane data-handling, such as MuBu... (ahem)