Forums > MaxMSP

Distances-in-list

Nov 02 2008 | 11:00 pm

Hello,

It is late and my brain does not work anymore to solve
this simple problem:
I want to find the distances of a list
L=(a1, a2, a3,…,an)
I would like to get
DL=(a2- a1, a3-a2,…an-an-1)
could you help me ?

thanks

sg

Nov 02 2008 | 11:10 pm

On 3 nov. 08, at 00:00, s.gaxie wrote:

> Hello,
>
> It is late and my brain does not work anymore to solve
> this simple problem:
> I want to find the distances of a list
> L=(a1, a2, a3,…,an)
> I would like to get
> DL=(a2- a1, a3-a2,…an-an-1)
> could you help me ?

like [mxj ej.x2dx]? I’ll see you in class ;-)

ej

Nov 03 2008 | 12:17 am

Here’s an abstraction method. And thanks Emmanuel that made me smile after a fairly awful day =)

lh

— Pasted Max Patch, click to expand. —
Nov 03 2008 | 12:29 am

Nov 03 2008 | 12:40 am

;-) Some other solutions bellow, just for the fun.

ej

I just did not know that [!-] takes list !

thanks

sg

Nov 03 2008 | 9:22 am

On 3 nov. 08, at 01:40, "s.gaxie" wrote:

> I just did not know that [!-] takes list !

All the operators (+, *, -, /, %…) can take a list of 2 elements.
There’s a kind of embed unpack.

ej

Nov 04 2008 | 8:45 am

Emmanuel Jourdan schrieb:
> some other solutions bellow, just for the fun.

I think it should not take more than two standard objects… ;-)
(works only up to 256 elements till the limit of vexpr is upped…)

— Pasted Max Patch, click to expand. —

Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
— _|_)—-|—–()————–
———-()——–www.ccmix.com

Nov 06 2008 | 12:22 am

Quote: stefantiedje wrote on Tue, 04 November 2008 00:45
—————————————————-
> Emmanuel Jourdan schrieb:
> > some other solutions bellow, just for the fun.
>
> I think it should not take more than two standard objects… ;-)
>

one object, js.

var myVector = new Array();

function list(){
myVector.length = 0;
myVector[0] = 0;
for (i=1; i
{
myVector[i] = arguments[i]-arguments[i-1];
}
outlet(0,myVector);
}

mz

Nov 06 2008 | 12:27 am

On 6 nov. 08, at 01:22, mzed wrote:

> one object, js.
>
> var myVector = new Array();
>
> function list(){
> myVector.length = 0;
> myVector[0] = 0;
> for (i=1; i
> {
> myVector[i] = arguments[i]-arguments[i-1];
> }
> outlet(0,myVector);
> }

Don’t forget the declaration of your i variable, otherwise you loose
the game ;-)

ej

Nov 06 2008 | 6:01 pm

Quote: Emmanuel Jourdan wrote on Mon, 03 November 2008 10:22
—————————————————-
> All the operators (+, *, -, /, %…) can take a list of 2 elements.
> There’s a kind of embed unpack.
—————————————————-

Just to further elucidate: for *any* object, a list message to the left inlet will distribute the list items over the other inlets.

The Max message-passing engine does this for all objects that don’t have their own list-handling method. IOW, if you click on the left inlet (ctrl-opt-click pre-Max5), and if you *don’t* see the item ‘list’ in the menu, the Max engine performs this bit of magic.

Objects that explicitly implement the list message will do whatever their documentation says they do (hopefully!)

This sort of comes up in the tutorials, but I became really aware of the behavior when programming lp.sigma & Co. (Sorry, I thought this was going to be a Litter Power-free post, but that was where I had to figure this out.)

HtH — P.

Nov 07 2008 | 5:51 pm

Emmanuel Jourdan schrieb:
> On 6 nov. 08, at 01:22, mzed wrote:
>
>> one object, js.
>>
>> var myVector = new Array();
>>
>> function list(){
>> myVector.length = 0;
>> myVector[0] = 0;
>> for (i=1; i
>> {
>> myVector[i] = arguments[i]-arguments[i-1];
>> }
>> outlet(0,myVector);
>> }
>
>
> Don’t forget the declaration of your i variable, otherwise you loose the
> game ;-)

using js to reduce the amount of objects needed is cheating, you’d then
have at least to add each function and each operator as well to the
bill… ;-)

In theory you could solve any problem entirely in js (or mxj), but you’d
need pretty many lines of code eventually, and you would actually avoid