# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

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

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?

Message 1 of 6
(504 Views)
Solution
Accepted by topic author DPM@ch

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

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

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
(474 Views)

## Rif.: Float to Enum (or how to create value for case selection)

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
Message 3 of 6
(472 Views)

## Rif.: Float to Enum (or how to create value for case selection)

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

Message 4 of 6
(468 Views)

## Rif.: Float to Enum (or how to create value for case selection)

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
Message 5 of 6
(459 Views)

## Rif.: Float to Enum (or how to create value for case selection)

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.

"Should be" isn't "Is" -Jay
Message 6 of 6
(449 Views)