From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structure: case for a range of values

I am trying to code a case structure where each case is performed when a numerical value falls within a certain range. Example:
Let say I have a sequence of values: 1,4,3,7,10,16,...
For values between (0-5) case 0 is perform, (6-10) case 1, (11-15) case 2, ... etc

What is the most efficient way to write this code with lv?
0 Kudos
Message 1 of 5
(11,499 Views)
The cool thing about LV is that many thing are polymorphic and adapt to what you input. in this case, you can wire the numeric into the selector terminal and then you can select the values in the label.
use ".." for a range and "," for multiple ranges. For example, you can have a case where the label will say "1..5, 9..12, 14, 17". This case will execute for these numbers.

___________________
Try to take over the world!
Message 2 of 5
(11,495 Views)
My numerical values are actually in the form of decimal eg 1.10, 1.23, 3.22 etc. I tried and was warn of the "selector of the wrong type".
0 Kudos
Message 3 of 5
(11,492 Views)
If possible, use integers (11..16). If not, and you have to seperate your groups between integers (11.6 and 11.7 belong to different cases) you can use the In range function from the comparison pallette. If you insist on having them in the same case structure, you can write a small VI to calculate which group the number is in and wire this into the selector. You can keep your values in a 2D array and deduce the number of the group from that.

___________________
Try to take over the world!
Message 4 of 5
(11,486 Views)
Then my best chance for a painless code would be to multiply these number with a factor of let say 100 or 1000 and round them off to the nearest integer and apply the range in the case selector. I think this would do the trick as the accuracy of the numbers is not a concern. Thank you for your time 🙂 You've been a great help.
Message 5 of 5
(11,483 Views)