From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

convert scalar to boolean

Hi.
I have created an array which contains 13 elements. These elements are scalars (double, 64 bit real) with the values 0 and 1. The array is initialised with 0s and the number of 1s is defined by user input. The VI is attached.
I want to extract each single scalar from the array and afterwards convert them to boolean variables. How can I achive this?
Thanks for help.
0 Kudos
Message 1 of 4
(2,738 Views)
To extract elements from an array, you can use the Index Array function or an auto-indexed for loop. To convert 0 or 1 to a boolean simply use the Not Equal to Zero VI from the comparison pallette - if the number is 0 you'll get an F and if it isn't you'll get a T. However, the nice thing about LabVIEW is that you can often perform the same actions on different types of things. In this case you can wire the array directly into the Not Equal to Zero VI and you'll get an array of booleans - each corresponding to an element in the original array. Here's an example that shows all three.

___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(2,730 Views)
Thanks for your quick answer. Meanwhile I was able to solve the problem. Did it similar to your suggestion. My problem was that I didn't think of the comparison palette which offers simple solutions to my question. My fault. ;o)
Anyway thanks for help!
0 Kudos
Message 3 of 4
(2,727 Views)
The other thing to be careful about is that the binary and decimal representations of numbers can produce results which may not be what you expect. When doing comparisons on non-integer numbers it is safer to compare to a range rather than comparing equality. If your ones and zeros are the result of a calculation, a zero might be 1.2838453-82 and a one might be 0.999999999999999... Comparing to 0 or 1 will give a Not Equal result. The In Range and Coerce function is useful in cases like this. Another approach is to compare to a threshold between the values. If x > 0.5 then true, else false.

Lynn
0 Kudos
Message 4 of 4
(2,709 Views)