LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulties with Case Structure

Solved!
Go to solution

While using a case structure, I got a problem with the case structure. I need the case structure to change a vlue depending on the case input provided.

 

however, the case inputs( boolean)  i want to give to the case stucture are  '<0' , '=0', '>0'.here I can only provide the case structure with >0 or <0.

 

How can I include the condition '=0' in the case input so that the case structure

1.   decreases the value of the parameter if the case is '<0'  ,

2.   does not change the value of parameter if the case is '=0' ,

3.   increases the value of parameter if the case is '>0.

 

I have included the VI that I am working on for illustration.

 P.S-  The VI has a knob to vary the input variable, and has a numerical indicator to view the output variable from the case structure. so, the numerical indicator should be constant if the input variable is not varied.

 

 

Thank You in advance.

 

 

 

 

0 Kudos
Message 1 of 13
(6,273 Views)

I cannot open your VI, but you could use '..-1', '0' and '1..' (instead of true/false) if the values are integer values or can be converted to integer.

Message 2 of 13
(6,261 Views)

HI,

 

Unable to view your code as it is developed in LV 2014.

 

Find the attached snippet.

Hope it resolve your issue.

 

Case structure.png

 

Regards,

 

Bijay

0 Kudos
Message 3 of 13
(6,251 Views)
Solution
Accepted by topic author harsha0209

As other have said, you can wire the numeric directly to the case selector and create ranges.  Since you will get wierd rounding when you use the floating point data types, use the Sign function (in the numeric palette) to convert your difference into [-1,0,1] and then use that result for the case structure.


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 4 of 13
(6,211 Views)
With numeric case structures, you can (in addition to specific values) define less than, greater than and even ranges.

Less than 0 would be: ..-1. (Less than or equal to -1)
Greater than 0 would be: 1.. (Greater than or equal to 1)
Between 5 and 10, inclusive: 5..10

You can also.combine them:

..3, 6..9, 42..

Would be less than or equal to 3 OR between 6 and 9 inclusive OR greater than or equal to 42

Case structures are also smart enough to recognize unsigned numbers and not accept negative values.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 13
(6,210 Views)

The comparison operators (=, <, etc.) are binary -- they give you yes/no answers.  Your question is ternary, three possible outcomes.  If you want to use binary comparisons, you need two of them (which gives you 4 choices, so you throw one away).  Note that a "mapping" strategy suggested earlier is probably better when dealing with more than three cases, but if you are just learning LabVIEW, sometimes the "simple way" is easier to grasp.  Note this is a Snippet, so you should be able to paste the image in LabVIEW 2014 and see the other cases (though they should be obvious -- the inner "False" says ">0 Case") and the outer "False" says "<0 Case").

 

BS

Case Question.png

0 Kudos
Message 6 of 13
(6,174 Views)

I would go with the sign function directly. No case structure needed!

 

Here's how your code would look like.

 

Message 7 of 13
(6,162 Views)

Thank you crossrulz. I have converted the binary decision in to three numbers Using the following method. And thanks for all the replies.

 

Screenshot (6).png

0 Kudos
Message 8 of 13
(6,123 Views)

That is Rube Goldberg Code .  Why do it that way when you can use the Sign function Altenbach shows which does it in a single node?

 

Heck, the middle of your construct there is completely pointless because it adds 0 whether the original number is equal to zero  or not equal to zero.

 

Here is Altenbach's code saved as a vi.

0 Kudos
Message 9 of 13
(6,115 Views)

@altenbach wrote:

I would go with the sign function directly. No case structure needed!


I need to spend more time searching the functions palette aimlessly.  It amazes me that there was a function I had never seen in the middle of the Numeric palette.

Matt J | National Instruments | CLA
0 Kudos
Message 10 of 13
(6,087 Views)