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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Float to Enum (or how to create value for case selection)

Solved!
Go to solution

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?

0 Kudos
Message 1 of 6
(1,033 Views)
Solution
Accepted by DPM@ch

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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(1,003 Views)

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 6
(1,001 Views)

@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:

case_selection.png

 

I will look into Threshold 1D Array mapping.

0 Kudos
Message 4 of 6
(997 Views)

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.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 6
(988 Views)

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:

case_selection.png

 

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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 6
(978 Views)