Forums > Jitter

# If then else in Jitter Matrix?

April 25, 2010 | 6:37 pm

Can anyone tell me if it’s possible to put an if statement into a matrix calculation?

Basically, I’m taking 2 matrices, and using a few jit.op objects for some functions (such as multiplying, adding etc) and outputting values in matrix form. The problem is I don’t want to end up with any values less than 1, so anything <1 I want to replace with the value 1.

I’ve done it in Max before, whereby I use:
if \$f1<1 then 1 else \$f1

Is there a way to do this in a matrix format in jitter?

April 25, 2010 | 8:15 pm

you have to make use of jit.expr to construct an equivalent expression using equality and logical operators.
one way to achieve your stated goal:
@expr (in[0]1)*in[0])

breaking this down, we are testing if the input is greater than 1, and multiplying this result (which will be 1 if greater than 1) with the input. this yields either the input if input is greater than 1, else 0.
we can then add this to the result of comparing if the input is less or equal to 1, which basically turns the 0s to 1s.

– Pasted Max Patch, click to expand. –

April 25, 2010 | 9:08 pm

This is genius…thank you!!

March 5, 2014 | 3:19 pm

Hi,

So is there a way to do "else"?

Thanks

March 6, 2014 | 4:09 pm

What exactly are you trying to do? The if/else construct doesn’t make a lot of sense with matrix processing since you always output a value for a given cell. If you have two different expressions you want to evaluate depending on some condition, there are a number of ways to implement it, but how it’s implemented might depend on exactly what you’re trying to accomplish.

Viewing 5 posts - 1 through 5 (of 5 total)