LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate number based on range of input

Solved!
Go to solution

Hello,

 

I am attempting to enter a case structure based on an input value if it lies within certain ranges.  For example, if the input is between 100-200, generate "1", 201-300 generate "2", 301-400 generate "3" and so on.  I am not sure how to implement this in LabVIEW.

 

I was attempting to use the "in range and coerce" but I will have to do that 5 or 6 times to test if the input is in the correct range, depending on the ranges that I have to test.  Is there an easier way to do this?

 

Any help will be greatly appreciated.

0 Kudos
Message 1 of 7
(2,877 Views)

Convert your DBL in question to an I32 and use it as the case selector. You can specify ranges for cases. "100..200" will execute whenever the value is in that range (inclusive). "1000.." will execute if the value is 1000 or greater.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 2 of 7
(2,873 Views)
Solution
Accepted by topic author hiNI

Hi hiNI,

 

I could not open your VI but here is what you might be looking for: (See how case values are entered).

 

Case selector.png

Check attached VI snippet.

 

EDIT: Also, any undefined value will be handled by the "default" case.

Message 3 of 7
(2,864 Views)

I would recommend to make the code more scalable and not hardwire all these boundaries into the case structure or into diagram constants scattered everywhere.

 

Typically you would simply threshold into a non-descending array of limits and use the returned rounded index.

 


@hiNI wrote:

I am attempting to enter a case structure based on an input value if it lies within certain ranges.  For example, if the input is between 100-200, generate "1", 201-300 generate "2", 301-400 generate "3" and so on.  I am not sure how to implement this in LabVIEW..


Your problem description is incomplete. For example you don't define what should happen if the input is below 100, for example.

 

With your current ranges there is even a simple math solution, right?

 

0 Kudos
Message 4 of 7
(2,863 Views)

@altenbach wrote:

With your current ranges there is even a simple math solution, right?


One simple possibility.

 

(Might need minor adjustments depending how you want to define the boundaries. Nothing a +1 or -1 or rounding operation in the right place could not fix. :D)

 

altenbach_0-1627484949404.png

 

Message 5 of 7
(2,849 Views)

Hello Altenbach,

 

Thanks for your input.  There is no use case for me below 100, but I should have specified that!

 

I do not immediately see an easy math solution as you mentioned.  Can you give me a little nudge as to how I can do this mathematically?

 

Thanks!

0 Kudos
Message 6 of 7
(2,837 Views)

Just to be clear, the original input is floating point, not an integer. For orange datatypes, you also need to worry about quantization due to the inherent limitations of the datatype, especially if the boundaries are fractional or the input is derived from a calculation (For example adding 0.1 10 times in a row will not give you exactly 1)

 

If the input is DBL, you need to make sure that the code handles all possible values from -Inf to +Inf and even NaN. You can typically use the default case for anything that does not need any special processing.

0 Kudos
Message 7 of 7
(2,795 Views)