How do I implement a multi-conditional statement using a Formula Node, such as the following?
if (x > 0 && <= 10) y = 1
else if (x > 10 && <= 20) y = 2
else if (x > 20 && <= 30) y = 3
else if (x > 30 && <= 40) y = 4
else y = 0
The solution depends on the version of LabVIEW you are using. All versions of LabVIEW support the solution outlined in the Older Formula Node Syntax section. LabVIEW 6.x and greater adds the use of C syntax. Both solutions are outlined below. For additional help, please refer to the VI, Function, & How-To Help by pressing ctrl+shift+?.
if (x>0 && x<=10)
else if (x > 10 && x<= 20)
y = 2;
else if (x > 20 && x<= 30)
y = 3;
else if (x > 30 && x<= 40)
y = 4;
y = 0;
Use the following syntax to implement a multi-conditional statement:
<variable> = <condition> ? (true case):(falsecase);
For this example:
y = ((x > 0) && (x <= 10)) ? 1:((x > 10) && (x <= 20)) ? 2:((x > 20)
&& (x <= 30)) ? 3:((x > 30) && (x <= 40)) ? 4:0;
Collaborate with other users in our discussion forums
A valid service agreement may be required, and support options vary by country.