03-10-2022 05:35 AM - edited 03-10-2022 05:35 AM
Might be a very stupid question - but I can't find an easy to read solution to get an enum value from a float value for case selection. Lets say I hav a value x, and now I want to use a case-structure for more than 2 cases (so a simple select does not work):
case1 - ok: 0.95 < x < 1.05
case2 - too small: 0.5 < x <=0.95
case3 - far too small: x <= 0.5
case4 - too large: x >= 1.05
How is this done in Labview?
Solved! Go to Solution.
03-10-2022 07:29 AM - edited 03-10-2022 07:32 AM
Use the Threshold 1D Array with an array as a look up table. The array will need to be constantly increasing, so set up your enum accordingly. The other nodes are Round Toward -Infinity (to make an integer value) and Coerce To Type (to convert the index to the enum).
03-10-2022 07:30 AM
Of course you can do it using a combination of simple comparisons, In Range and Coerce and multiple Selects or nested Case structures.
If your inequalities would be symmetrical (i.e. case1 - ok: 0.95 < x <= 1.05, case4 - too large: x > 1.05 ), it would be perfect to use Threshold 1D Array mapping the result to the desired enum value.
03-10-2022 07:39 AM
@pincpanter Its not that I can't solve the problem - but its horrible to read, maintain or extend. Right now I have a sub-vi like this:
I will look into Threshold 1D Array mapping.
03-10-2022 07:52 AM
Unless you expect to receive exactly 1.05 (but why bother about it?), crossrulz already gave you the solution.
If your enum already exists, create an array constant with ordered cases (far too small, too small, etc.) and use crossrulz's code output as an index to pick the right constant.
03-10-2022 08:14 AM
DPM@ch wrote:
@pincpanter Its not that I can't solve the problem - but its horrible to read, maintain or extend. Right now I have a sub-vi like this:
I will look into Threshold 1D Array mapping.
Looks like great code (for an Aztec) But, they also used slave labor to build and maintain their pyramids.
Use the threshold method.