Forums > MaxMSP

### substitute numbers in list

Apr 08 2013 | 9:04 am

I have a message object which fills itself with a list.
This list can contain the number 1-48.
However, the numbers the list shows, and the length of the list vary, depending on sensor input. My goal is to cluster the data in this list.

I want all numbers in a range of 4 to be substituted with its mean number.
So 1 2 3 4 = 2.5 = 3 (no floats allowed)
or 2 4 7 10 12 = 7
or 44 45 = 44.5 = 45

However, a list can contain more numbers that the ones merged together. For instance:
1 2 3 4 44 45 = 3 45
2 4 7 10 12 21 28 44 45 = 7 21 28 45

How can I program this?

Apr 08 2013 | 9:25 am

Hello,

I’m not sure some of the arithmetic in your examples is correct- either that or I don’t understand what you want.

I think this is what you’re after. I strongly suggest you look at zl.maxhelp for a clear understanding of what it does.

``````
-- Pasted Max  Patch, click to expand. --

```
Richard
```
Apr 08 2013 | 9:43 am

Sorry I wasn’t totally clear. It is a bit more complicated.
With number in a range of 4 I mean x+4 or x-4. Not the length of the amount of numbers.

So in this series of numbers: 2 4 7 10 12 21 28 44 45
2 4 7 10 12 vary with 4 or less. (12-10= 2, 10-7=3, 7-4=3 etc.) so I want the mean of these numbers to show.
21-12 = 9 which is higher than 4, and therefore makes the start of the next range.
28-21 = 7 so is also the start of a next range.
44-28 is also higher than 4
45-44 = 1 so the mean should be shown.

So: 2 4 7 10 12 21 28 44 45
Results in: 7 21 28 45

Apr 08 2013 | 9:54 am

Try this – notice how the [t] and [-] objects are connected, that is the trick, all the rest is plain fare!

hth
aa

``````
-- Pasted Max  Patch, click to expand. --

```
```
Apr 08 2013 | 9:59 am

Thanks!!
I had been working on it for ages, you made my day!

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > MaxMSP