08-27-2015 07:53 PM
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.
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
Solved! Go to Solution.
08-27-2015 07:56 PM
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.
08-27-2015 08:03 PM
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.
08-27-2015 08:04 PM
@RUR wrote:
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.
08-27-2015 09:17 PM
@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.
09-01-2015 12:29 PM
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!