round values to next in list...

PlinioDesignori's icon

really simple problem i think, but i cant think of any simple solution - maybe you guys have an idea how to do this:

I have a list of variable length with floats. eg: [10. 34.5 50. 72.] and an input value from 0. to 100.. now what i want is a simple function wich outputs 10. for the input range of 0. to 10.; 34.5 for the input range of 10.000001 to 34.5; 50 .... ect. you get the idea.

whats the easiest and most efficient way to create such a function with a variable number of points?

best,
plinio

PlinioDesignori's icon

i thought about writing the values into a buffer and reading from that - but thats to much msp for me...

PlinioDesignori's icon

okay - for now i used the function object - looking for better ideas though.

spectro's icon
Max Patch
Copy patch and select New From Clipboard in Max.

With a handful of values like you have, [split] could work. The challenge might be assigning the min/max and output values as the input list changes

Roman Thilenius's icon

if the lists are short, say of 5 elements, something like split would be perfect.

if the lists contain 100 elements, you better try to iterate it and build the process around single elements.

ak's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I call this "quantize to list". Enjoy :)

Johann's icon

here's my solution with an iterative process. Note, here I'm rounding to the nearest value in the list. So it's not always rounding up or down. So it's a bit different than the OP requested. However it's a 10 year old issue anyways. Just posting for documentation :), in case someone needs it. Or if anybody has a more elegant idea, I'd be curious.

Max Patch
Copy patch and select New From Clipboard in Max.
Jeremy's icon

@ak's solution is very elegant.

Roman Thilenius's icon

max 4 version. ;)

the stuff in the panel is [zl.sum]

but it also depends on the list beeing sorted already.