Forums > MaxMSP

Absolute Value Of List Values

November 14, 2007 | 6:44 pm

Hi all,
What might be the best way to take a given list (say 100 float values with some negative numbers and some positive) and perform an absolute value operation of all the numbers (and prepend the result into another list.) Basically, I need to format a list that has negative values into a new list with the same values, except the negative floats are now positive.
I guess i could unpack all floats, repack them once i’ve used |abs 0.| but that seems a little intense for lists that could be very long.

Thanks for the help!
-kp


November 14, 2007 | 6:57 pm

hi.
try with [vexpr abs($f1)].
best.


November 14, 2007 | 7:02 pm

On 14 nov. 07, at 19:44, kevin pooler wrote:

> Hi all,
> What might be the best way to take a given list (say 100 float
> values with some negative numbers and some positive) and perform an
> absolute value operation of all the numbers (and prepend the result
> into another list.) Basically, I need to format a list that has
> negative values into a new list with the same values, except the
> negative floats are now positive.
> I guess i could unpack all floats, repack them once i’ve
> used |abs 0.| but that seems a little intense for lists
> that could be very long.

You can do that with vexpr.

ej

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 18 186 19 196617 1;
#P comment 18 266 19 196617 0;
#P comment 18 54 19 196617 1;
#P user multiSlider 36 191 332 81 0. 1. 256 2681 47 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 36 159 79 196617 vexpr abs($f1);
#P user multiSlider 36 58 332 81 -1. 1. 256 2681 47 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P comment 15 134 19 196617 -1;
#P connect 2 0 3 0;
#P connect 1 0 2 0;
#P window clipboard copycount 7;


November 14, 2007 | 7:37 pm

On 14-nov-2007, at 19:44, kevin pooler wrote:

>
> Hi all,
> What might be the best way to take a given list (say 100 float
> values with some negative numbers and some positive) and perform an
> absolute value operation of all the numbers (and prepend the result
> into another list.) Basically, I need to format a list that has
> negative values into a new list with the same values, except the
> negative floats are now positive.
> I guess i could unpack all floats, repack them once i’ve
> used |abs 0.| but that seems a little intense for lists
> that could be very long.
>
> Thanks for the help!
> -kp

Labs from Lobjects by Peter Elsea
see http://www.maxobjects.com for details
HtH
-jennek


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