LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable in case selector label

Solved!
Go to solution

Hello everyone.

Probably it's a trivial problem but I can't work it out.

I need to create a case structure with 3 cases:

First case if x < c

Second case if x = c

Third case if x > c

where both x and c are variables. I can't believe the only way is nested case structure. I know selector labels can contain a range like 0...4, but what if instead of 4 I have a variable (c)??

Any help is really appreciated.

Matteo

0 Kudos
Message 1 of 5
(4,021 Views)
Solution
Accepted by topic author matteo.bart

Subtract your numbers.  Then in the numeric palette is a function called "Sign".  It will return -1, 0, or 1 based on the sign of the value passed into it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 5
(4,006 Views)

Yes,that was really easy. I had not seen Sign function. Thank you very much.

0 Kudos
Message 3 of 5
(3,985 Views)

Be careful. That may not work for all cases. There is always a problem in comparing DBLs to zero or to each other (i.e., x=0  or  x=y). I attached a snippet as an example.

 

If you type in the values of 0.1 directly into the controls, the result of the "Sign" is as expected.


If the Values are computed from other control  values you get an unexpected results
I SUBTRACTED two DBLs and the results is ~0.1
I DIVIDED two DBLs and the results is also ~0.1

However 0.1 - 0.1 <> 0 in this case. The results of the "Sign" function is 1!!

 

case selecytor.png

0 Kudos
Message 4 of 5
(3,969 Views)

You're right. In my case I subtract integers so it's ok. Thank you for the clarifications anyway.

0 Kudos
Message 5 of 5
(3,959 Views)