LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

if then structure for more conditions

Hi everyone,

I want to use a structure in my vi such that,

 

if a=1,  I want to use a numeric value of 5

if a=4, I want to use a numeric value of 10

if a=8, I want to use a numeric value of 20   and so on...

 

How can I achieve this? Using a case structure adding more case or somewhat? Could you please help me?

0 Kudos
Message 1 of 6
(2,812 Views)

Yes, you would use a case structure and create cases for each value (or range) that you need. You will also need a default case. A case structure does not have to use a Boolean for the selector. It can use numbers as well. As mentioned, you can specify ranges if you need.

 

For example, a case can be defined for a single number (case label would be "5" for example), multiple numbers (case label would be "1,2,5,8,10" for example) or a range (case label would be "1..10" for example).

 

Numeric case.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 6
(2,810 Views)

Hi,

I want to use 13 different conditions. I attached a file in which two of them is given. If frequency=0,1 Hz, the constant as output will be 1,25. If frequency=0,2 Hz, the constant as output will be 1,5 and if freq.=0,4.......and so on. For 13 different frequency value, there will be 13 different output constants.

 

I tried to use enumerated case structure, but I failed. Could you please help me? and construct a small demo? Thanks..

0 Kudos
Message 3 of 6
(2,785 Views)

You should attach your actual VI instead of a picture, this way we can see what you have and also tell what LabVIEW version you are using.

 

Cases accept integers, in this case you would wire the number directly to the case selector.

 

Since you are dealing with fractional values, you should probably simply use a lookup table. No case structure needed.

 

Do you have a list of all value pairs?

0 Kudos
Message 4 of 6
(2,777 Views)

Hi altenbach,

I can not attach the actual vi. Because you can not open it due to not having daq card sub vis. Also, the vi is too complex to understand quickly. I attached the pairs of numbers.

I have a control to select the frequency.

As a result of these selected frequencies, there are corresponding numeric values to use them in another mathematical operations. For example if I select the frequency as 0.1 Hz, the output constant must be 1.25. If I select frequency as 0.2, the constant must be 1.3 and so on.

 

In other words, when I take data for 0.1 Hz, in some part of the mathematical operation the constant must be 1.25.

So, if freq.=0.1, the output is 1.25 to use it anywhere;

      if freq.=0.2, the output is 1.3;

      if freq.=0.4, the output is 3.2 and so on.

 

Freq.          constant

0.1             1.25

0.2             1.3

0.4             3.2

0.6             4.2

0.8             6.2

1                6.8

2                17

4                23

6                45

8                94

10              120

12              145

14              180

0 Kudos
Message 5 of 6
(2,774 Views)

 


mechen wrote:

I can not attach the actual vi. Because you can not open it due to not having daq card sub vis. Also, the vi is too complex to understand quickly.


 

I can open any VI, but it might be broken. Why would that prevent you from being able to attach it? 😮 That's backward logic.

 

Don't make assumptions on what I can, and cannot understand. You can easily delete everything except the important parts. You still have not told me your LabVIEW version, which would have been obvious if you had attached the VI.

 

Your specifications are very incomplete. For example you don't say what should happen if an input value is different from the 13 input values listed. What if the input is out of range? How do you ensure that only the 13 inputs are possible?

 

The attached VI (LV 8.2) has two possible solutions. The upper part interpolates for inexact inputs, while the lower part returns zero for inexact inputs. The upper part is much safer because it will return pretty good outputs even if the inputs are not exactly right due to the limiations of floating point representation.

 

This is just a starting point. You need to decide how to handle input errors. Makes sense? There are many other ways to do all this. Modify as needed.

Message 6 of 6
(2,768 Views)