From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
07-14-2011 10:57 AM
Hi, what I want to do is take a number, lets say 1.5 and campare itself to the range from 1.4-1.6, if it is within this range, then it'll return true, else false.
An easy way to do this is to have a case structure with a case selector of integers. However, the case structure can only take whole numbers (in my knowledge, such as from 1 to 3), so i cant do something like go into case 1.4 to 1.6 if the number passing into the case is within that range.
I'm sure there's an easy solution but I haven't thought of it, any help would be greatly appreciated.
Thank you.
07-14-2011 11:01 AM
The easiest way is to use the In Range and Coerce VI (Comparison palette).
You can also set case structures to ranges like this: 1.5 .. 2.0 (case selected when input is 1.5 < x < 2.0)
07-14-2011 11:04 AM
@NIquist wrote:
You can also set case structures to ranges like this: 1.5 .. 2.0 (case selected when input is 1.5 < x < 2.0)
That only works with integers, a case structure converts floating point numbers to I32.
07-14-2011 11:12 AM
Oh Yeah, you're right. I guess floats would be tricky to use to select cases due to rounding issues. It would be a nice feature if it could be logically supported though.
07-14-2011 11:15 AM - edited 07-14-2011 11:22 AM
Well Niquist is half right- use inrange and coerce since Case structures only work on integer data types (bools, strings, U32 etc) and dont work with Floats. (Would be nice sometimes but, thats what IR&C is for). Typing floating point litterals in the case selector tells the case to expect strings and breaks the vi unless a string is wired.
Scanning a float to string doesn't help much either since the "." char value (46) is less than every number value (48-57) and "+" is less than "-"-
07-14-2011 11:35 AM
You can also simply multiply the float by 10 (if you're just at one decimal point precision) and then use integer values. Just be sure to use the numeric conversion functions to get an integer so you can wire it to the case structure.
07-14-2011 11:58 AM
In case you were not aware, IR&C can be adapted to check multiple ranges as well.
Notice that the Radix of the Case structure is set to Binary. I use this when the ranges do not overlap. Otherwise you can handle the Boolean array element by element.
07-14-2011 12:33 PM
Darrin- That belongs in the micro-nugget thread. Criminey, Neither the help nor the shipping example hint at the ability to compare scalars to arrays of paired limits. Where did you discover that?
07-14-2011 12:39 PM
Thanks for the replies... The multiply by 10 techique works to an extent. When you're sending in 13.6 into the case, it'll round up and go into case 14-16 instead of the default case (only two cases) which doesn't work for me.
I thought of a solution though, what I did was compare the number (1.5) to 1.4 using greater than function and again comparing 1.5 to 1.6 using less than function THEN anding the results which gets sent to a boolean case. So far, this solves what I'm looking for.
Thanks again.
07-14-2011 12:57 PM
@BurningH34t : You have described the longhand (borderline RG) version of the In Range? boolean output of the In Range and Coerce function. Which leads to Jeff's question. If you write out this longhand version of IR&C, it is easy to understand why it works as expected with arrays.
Simply change the comparisons to include either or both limits. This is what is "under the hood" of IR&C apparently. So of course my "discovery" was a result of careful consideration and in no way involved simply wiring things up to see what would happen...