### If then else in Jitter Matrix?

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?

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.

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
473.3oc0UF0SCBCDG+Y3SQSexMmKzNbyYTy9T3KKKKEnaqZok.2TTie2EJvD
LyMbtrnOPa45wc+uekCdy1B6oS4IXz0noHKq2rsrLlxMXUduENjk5KYIF2vO
Hf99bozSp8eD2qvinXdBWALPnUyi49PQDIiH8c5gnWQymbJGPyJeJ05PgRxA
SfoeZTuFpr5Vk.F3uRnVVO3W4TD75SiqGeesrQPDAlJP68vEipT9BsBTrPtY
m64wALEqZuBc.uDwKxHVJR.bODdy0lTEqetQpxCah3UyCRxzTt02ssyG50RP
q3OmozJs.7TXC+4oQwnIlwyDpoNyt4VRmyOqX8cjNcMK5faOmo6fyzB.6ZlF
3XNKIiqw4Zbc3Aw0rZZdHChEoMo5QfhdqAPq1JIHakDj8ShuLtMNb42VqdL0
xrJ7.Jks14cT5gHtGROzf+08P5HzjrqtnIOwjHZ+iZyBwoXh3tqlE5eslkcf
KkVjvQDzBolACnHWj6OnoZ+DaXIvFuKfQNU.y3S1qppu9uQSAjauIESzqi8q
xW4QK5yRHfm.Bk4ui07YXCeVIBB3lscJsDJBhzBETJgu4aFsUQCaghFcRUzk
sPQjSphZyo1fSphHsPQzeghxt4c6ObTOTEB
-----------end_max5_patcher-----------
```

This is genius…thank you!!

Hi,

So is there a way to do "else"?

Thanks

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.

Forums > Jitter