07-28-2021 09:46 AM
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.
Solved! Go to Solution.
07-28-2021 09:54 AM
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.
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.
07-28-2021 10:01 AM - edited 07-28-2021 10:02 AM
Hi hiNI,
I could not open your VI but here is what you might be looking for: (See how case values are entered).
Check attached VI snippet.
EDIT: Also, any undefined value will be handled by the "default" case.
07-28-2021 10:01 AM - edited 07-28-2021 10:04 AM
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?
07-28-2021 10:10 AM
@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)
07-28-2021 10:31 AM
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!
07-28-2021 12:36 PM
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.