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 for comparing values

Hi,
i just wanted to know if there is a special way to use comparison in case structures.

I only kow how to create cases for things like if x=0 then ... if x=1 then ...

Now I want to make it if x<0 then ... if x=0 then ... if x>0 then ...

The only solution I found so far is creating a case structure inside a case structure.

Is there a way to keep it all in just one case structure?

Thanks and have a nice weekend,
Bernie
0 Kudos
Message 1 of 20
(11,067 Views)
The In Range and Coerce function in the comparisons palette will give out 1,0 and –1 for values above, equal to and less than 1 and –1. See image for details
Yours Sincerely
John www.TradersMicro.com
0 Kudos
Message 2 of 20
(11,067 Views)
If you are comparing integers, you can use a range in the case structure. Case 0 would be "..-1", case 1 would be "0", and case 2 would be "1..".
Message 3 of 20
(11,067 Views)
Hi Bernie,
You can do that and many others things, using only one structure. I'm talking above "Formula node". See the help of this structure directly in LV, and you will find a very useful aid.

JFT
0 Kudos
Message 4 of 20
(11,067 Views)
Case Structures are pretty flexible in how you can specify what triggers a particular case. You can specify ranges or various values per case.

In your situation, if you specify three cases with the following values, you'll get what you want.
'..-1' = x<0
'0' = 0
'1..' = x>0

The two periods before or after a number indicate that the case should run if the value is anything less than or greater than the specified number, depending on which side of the number you place it. You can also use this to specify a range of number. '1..10' would trigger the case for any value 1 through 10. Using a comma between numbers lets you specify different non-sequencial numbers. '1,5,10' would run the case only those specified numbers.

The same basic rules a
lso work with text based Case Structures.

Attached image shows the three cases you need.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 5 of 20
(11,067 Views)
Thanks a lot for all your answers!

Now my diagram looks more cleaned up 🙂
[and I am a little bit smarter]
0 Kudos
Message 6 of 20
(11,067 Views)

Regarding the values used to define a given case structure, e.g. 0..10 for case 1 and 10..20 for case etc... can the values 0, 10, 20 etc. be input to the case structure through a numeric control?  In other words, if I want to use the values of the various case structures as parameters which will be varied each time I use the vi, how would I configure that? 

 

Right now, I can see only that the case structures are "hard wired" with the values used as limits.

 

Suppose case 1 is for  1<x<10

Suppose case 2 is for  10<x<20

Suppose case 3 is for  20<x<30

 

Now, suppose that I want to vary the values 1, 10, 20 and 30 to 3, 12, 22, and 32 etc.  Can I have a numeric control for each of the case structure values, instead of opening and editing the block diagram each time we want to vary these values?

 

Thanks,

Dave

0 Kudos
Message 7 of 20
(10,455 Views)

No.  You can't programmatically change the case structure conditions.

 

What I would do is make the comparisons and output a boolean for each comparison.  Build the boolean values into and array, and use Boolean Array to U8.  Feed that value to a case structure.

 

Now if the first condition is true, it will run the case called 1.

If the second condition is true, it will run the case called 2.

If the third condition is true, it will run the case called 4.

A fourth condition would run case 8.

Make the original case a 0; default which does nothing if no conditions or true, or if you come up with some situation where multiple conditions are true (which should happend if the conditions are formed correctly.)

Message 8 of 20
(10,448 Views)

I am still a little confused.  If you make each comparison have a Boolean output, then, won't the array be a list of 0's and 1's or T and F?  If there are only two unique values in the array, then, how does the case structure provide more than 2 actions?  What am I missing?

0 Kudos
Message 9 of 20
(10,435 Views)

You are missing the conversion of the boolean array to a number.  So  you now have essentially a binary number that uniquely identifies a combination of conditions.

 

See attached

Message 10 of 20
(10,429 Views)