LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

compare 1D array to a constant and output result as a single boolean

Solved!
Go to solution

Hi All, 

 

I am tryinig to compare a 1 D array of DBL to a constant of DBL when a button is pressed, and I want the output to be a single boolean only. However I can't seem to solve the problem. 

 

Compare_array_single_boolean_output02.JPG

 

When I run the block diagram, as long as one element in the array equals to the constant value then the output X = Y? will display true... however I want it to display true only if all the elements are equal to the constant value. How do I do that? 

 

This should be very easy but I can't seem to get it working the way I wanted to. 

 

Cheers,

Leon

 

0 Kudos
Message 1 of 6
(5,396 Views)
Solution
Accepted by topic author RUR

Get rid of the For Loop.  Compare the array to the constant.  You'll now have an array of Booleans.  Use OR Array Elements to get a True if any element is true.  Use AND Array Elements to get a True if all elements are true.

0 Kudos
Message 2 of 6
(5,393 Views)

To clarify, "compare" by Ravens meant to just plug the constant and the array into an =? node.  It already does the work of the for loop you're trying to build.

0 Kudos
Message 3 of 6
(5,381 Views)
Solution
Accepted by topic author RUR

@RUR wrote:

 

Compare_array_single_boolean_output02.JPG

 

When I run the block diagram, as long as one element in the array equals to the constant value then the output X = Y? will display true... however I want it to display true only if all the elements are equal to the constant value. How do I do that?


Actually, you will only see the output display true if the LAST element is equal to the constant.  Since you want to see if they are ALL equal, follow RavensFan's advice and not use the FOR loop, use Equals to do the comparison and have an array of booleans out, and then AND Array Elements to take it to a single boolean representing if all of the elements are equal.

 

Also realize that comparisons of floating point numbers is just asking for trouble.  If your numbers can only be integers, then use an integer data type like I32 instead of a floating point type.


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
0 Kudos
Message 4 of 6
(5,379 Views)

@natasftw wrote:

To clarify, "compare" by Ravens meant to just plug the constant and the array into an =? node.  It already does the work of the for loop you're trying to build.


Yes.  But since the OP used compare in the subject line and in the message, I figured they would understand that it meant the equals node.

0 Kudos
Message 5 of 6
(5,365 Views)

The answer was spot on... I was able to finish off the programmign and started test before Friday and got the result I wanted after the weekend. Thanks all the inputs! 

 

 

0 Kudos
Message 6 of 6
(5,289 Views)