Checking linearity of values [Solved]

Just Evan's icon

Hi!

I'm trying to implement a check - whether each new value (number) is really more or less than the previous one by one unit, in other words - differs from the previous one by 1.00, in order to detect sharp changes of values, by more than one unit.

Perhaps someone can help me with this? Maybe there is an object that can store previous numbers, or something like that...?

Just Evan's icon

UPD: My solution.

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

TFL's icon

The problem with your solution is that the result will be updated only 1 out of two values received, because of the [zl.group 2]. You could use [zl.stream 2] instead, or just a [trigger i i] with its rightmost outlet connected to the left inlet of the next object (a [-] or any comparator), and the leftmost outlet connect to the right inlet of that next object.

Also, in your message you speak about floats, but your patch is with integers. Do you want to compare floats or ints?

And more specifically, you said:

in order to detect sharp changes of values

so you can do this in a much more compact and robust form (compatible with both floats and ints):

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

Just Evan's icon

TFL, Oh thank you! Great solution!

But this makes me wonder, does [t f f] actually have a delay between each value being sent?

TFL's icon

There is no delay, it's just that the rightmost f is output before the left one. As you should know, in Max, events happen one after the other, never "at the same time" (except with parallel processing but that's another topic). To define the order of execution, Max have a few systems, including the scheduler (some events have higher priority than others), the position of the object in the patch (from bottom right to top left) and, for most objects, data is output from right outlet to left outlet. So a [t f f] will have its right f sent before its left f. There is no artificial delay, as the computer does it as fast as it can, but it's still "one after the other".

Roman Thilenius's icon

you can call it a "delay", but it is more useful to think about it as the "order".