Subtracting element from previous element within a list.

Michael's icon

Could someone please help me figure out how to perform a calculation on a list of numbers, where each element in the list is subtracted from the previous element to generate a new list of differences.

For example, if I have an input list of 2 4 6 7, i would like to generate a list of 2 2 1 by subtracting 2 from 4, 4 from 6, and 6 from 7.

Please note that the input list length will vary with different examples as this list will be dynamically generated.

Thanks in advance.

Source Audio's icon

you need to iter the list and form pairs of numbers to perform calculation.
remove 1st result, because it will contain last item from previous list.

Max Patch
Copy patch and select New From Clipboard in Max.

riccardo dapelo's icon

Something like this?
Surely could be done in a more elegant way. A rapid one:

Max Patch
Copy patch and select New From Clipboard in Max.

MakePatchesNotWar's icon

My take...

Max Patch
Copy patch and select New From Clipboard in Max.

Michael's icon

thanks, this is great.