# Conditional graph

## Recommended Posts

Hello,

I'm logging two channels, A and B, which I also present in two separate graphs.

I also have a third graph presenting the quotient A/B.

Now to my question; if the value of A is under a certain limit (in the example below = 0.2) I would like the third graph (A/B) to display 0.

Here's what I've tried without any success:

____

global quotient = 0

if (A[0]) < 0.2

quotient = 0

else

quotient = A[0]/B[0]

endif

____

I then try to call the quotient variable by just writing "quotient" in the y-expression field from within the third graph but this does not seem to work.

Marcus

##### Share on other sites

Yeah, that won't work because quotient is a scalar, among other reasons (such as the fact that your sequence isn't looping). The best way to do this is with simple boolean math directly in the Y Expression:

A/B * (A >= 0.2)

The boolean (A >= 0.2) will return an array of 0's and 1's, with 1 everywhere its >= 0.2. Multiply by A/B which is an equal sized array and you get 0 wherever A < 0.2