Forums > MaxMSP

Adding all values in a list.

April 7, 2008 | 3:46 pm

Is there any object or external that will take a list of integers and add all the values, outputting a single value.

In my case i have a patch which includes a constantly changing list of 25 integer values, for which i need the total value.

I currently have it set up like so:

[list] -> [unpack] -> [expr $i1 + $i2...] -> [number]

This works but is kinda messy, what with 25 values being outputted from the [unpack], and [expr] only supporting 9 inputs (meaning i need 3 of them, plus a further one to add the outputs of those).

Thanks in advance.

:)


April 7, 2008 | 4:32 pm

Have you looked at LObjects?

For that matter, you should try maxobjects.com, which would certainly point you to LObjects.


April 7, 2008 | 7:01 pm

Here’s a simple solution using accum:

Zachary

max v2;
#N vpatcher 10 59 330 334;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 94 214 97 196617 sum of all elements;
#N vpatcher 530 274 700 510;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 50 75 58 196617 random 10;
#P newex 50 50 40 196617 uzi 25;
#P newex 67 146 62 196617 prepend set;
#P newex 50 123 27 196617 t b l;
#P newex 50 99 61 196617 zl group 25;
#P inlet 50 30 15 0;
#P outlet 50 175 15 0;
#P connect 1 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 2 0;
#P connect 2 0 3 0;
#P connect 4 0 0 0;
#P connect 3 0 0 0;
#P connect 3 1 4 0;
#P pop;
#P newobj 49 67 68 196617 p randomList;
#P button 49 45 15 0;
#P newex 94 138 62 196617 prepend set;
#P newex 49 113 55 196617 t l 0;
#P message 49 92 237 196617 5 2 5 2 3 4 6 3 9 4 6 3 7 1 5 6 3 2 9 0 8 5 0 3 0;
#P newex 49 162 56 196617 t b i;
#P newex 49 138 25 196617 iter;
#P newex 49 188 103 196617 accum;
#B color 5;
#P number 49 213 43 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 66 45 122 196617 generate 25-element list;
#P connect 8 0 9 0;
#P connect 9 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 3 0;
#P connect 3 0 4 0;
#P connect 7 0 2 0;
#P connect 4 0 2 0;
#P connect 2 0 1 0;
#P connect 6 1 7 0;
#P connect 4 1 2 1;
#P pop;


April 7, 2008 | 10:51 pm

yet another option is [mxj list.sum]

-b


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