(Basic?) math Issue

MARTINUKAI 's icon

I am very tired so forgive me if the answer is quite obvious ;)

I want to use the output of a slider so that when the slider is at 0 it actually outputs a large value. And when the slider is at its highest point then it outputs something closer to 0. The slider is not important but just using it as a visual idea to get the scenario across.

So basically, if the slider is dropping from e.g.. 4 to 0..... 4, 3, 2, 1, 0...... I actually want it to output 0, 1, 2, 3, 4.

An issue is that I cannot predict the maximum value, as it is based on other changing data. All I know is that the values will never go below 0. So from 0 to "?".

So far maths is failing me so perhaps there is a dead easy solution to this I'm not aware of?

Any tips much appreciated :)

bkshepard's icon

Does this do what you want?

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

MARTINUKAI 's icon

Thanks, BKSHEPARD. That is exactly the outcome I want.... but the issue is that I cannot predict the maximum incoming value. I think in your example, you must manually set this max. Am I correct?

Perhaps I can expand. My fundamental problem is that I am dealing with values that go positive and negative across a 0 axis. I wish to output higher values as the graph swings closer to the 0 axis (either side of it).

Here is a screen shot of this scenario, graphed. Left is negative and right is positive.

Roman Thilenius's icon

1. it is impossible to map an unknown value to 0. you have to find it out or arbitrarily set the max number.

2. you can split an incoming range with split (or better with clip when the input is coming from mouse or sensor input), then reverse the positive range with !- 100. and the negative range with * -1. , !- 100. , * -1. .

3. as usual, it will also fit into one line:
expr ($f1<0.) * (-1. * ($f2 - (abs($f1))) ) + ($f1>=0.) * ($f2 . - $f1)

where the second input is the max number, i.e. expr ($f1<0.) * (-1. * (100. - (abs($f1))) ) + ($f1>=0.) * (100. - $f1)


MARTINUKAI 's icon

Thank you very very much, Roman :) I'll try this out asap and report back.

The "arbitrary" max number... I figured that was the issue.

Perhaps there is a way I can detect and store the last max (+) and min(-) as it sways back and forth and store that value temporarily to be input as "$f2"(the maximum) above.

Roman Thilenius's icon

if the data is coming from a sensor or a gaussian noise, i would do exactly that, let it run for 1000 times or for 3 seconds and then use minimum and maximum to find a useful forced limit.

bkshepard's icon

Since I didn't know where your unknown value was coming from, I just represented it with an integer object. My thinking was that whatever was outputting the unknown value would replace the integer object.

Pedro Santos's icon

You can store the last x values in a list with zl.stream, then find the min and max values from that list and use the scale object to adjust the scale dynamically, including reversing the output.

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

MARTINUKAI 's icon

Hi, BhShepard. I see your thinking now with the integer object. Thanks again :) Thank you once again also, Roman :)

Pedro Santos's icon

I'm feeling so alone and underappreciated... ;-)

MARTINUKAI 's icon

Hey, Pedro... I'm very sorry. I totally missed your message. I have opened your example patch now and it's really cool with the visualisation via the graph also. Thank you very much! Was not being rude ;)

Pedro Santos's icon

Martin, don't worry, it really was a joke!