Distances-in-list

Nov 2, 2008 at 11:00pm

Distances-in-list

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

#40627
Nov 2, 2008 at 11:10pm

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

#143881
Nov 3, 2008 at 12:17am

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

lh

– Pasted Max Patch, click to expand. –
#143882
Nov 3, 2008 at 12:29am

#143883
Nov 3, 2008 at 12:40am

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

ej

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

thanks

sg

#143884
Nov 3, 2008 at 9:22am

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

#143885
Nov 4, 2008 at 8:45am

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

#143886
Nov 6, 2008 at 12:22am

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

#143887
Nov 6, 2008 at 12:27am

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

#143888
Nov 6, 2008 at 6:01pm

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.

#143889
Nov 7, 2008 at 5:51pm

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
Max instead of using it…?

Stefan


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

#143890

You must be logged in to reply to this topic.