LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to compare array of integers and get an array of Booleans to display based on comparison

Solved!
Go to solution

Hello,

 

I have an array of integers. With this array, I want to compare each element to make sure it falls within a set bound of numbers (95 to 105 for this example). I compare this int, if it is within the range I want a boolean round LED to be green, and if it is not within the range I want the light to be red. My issue is, when I run what I have, the first value comparison is what is displayed for all 10 places of the test. Any idea why this might be? I attached screenshot of code.Capture.PNG

0 Kudos
Message 1 of 12
(234 Views)
Solution
Accepted by topic author LearningLabVIEW

Because you used an array for the high limit and low limit comparison, please change them into an element.

 

When you compare two arrays, comparisons occur for respective elements and are limited to the least number of elements of the two arrays. In this case, your array constant has only one element and hence only the first value was compared.

 

Array 1 > array 2 comparison gives the number of elements lesser of the two arrays

Array 1 > scalar value comparison gives the number of elements equal to array 1 - here each element of the array is compared against the scalar value.

-Santhosh
Semiconductor Validation & Production Test
Soliton Technologies
NI CLD, CTD
LabVIEW + TestStand + TestStand Semiconductor Module (2013 - 2020)
NI STS for Mixed signal and RF
0 Kudos
Message 2 of 12
(229 Views)

Hi ,

 

You can use in range function to simplify your code, and attach scalar values to limits if it is same for all values which are being compared.

 

bharathp10_0-1632371128263.png

 

bharath_p
LV2020
0 Kudos
Message 3 of 12
(184 Views)

Thanks for this. I had this originally but it wasn't working so I was just using this other method to see if it was something with the way I was setting it up. Will be using that tool though.

0 Kudos
Message 4 of 12
(174 Views)

@LearningLabVIEW wrote:

Thanks for this. I had this originally but it wasn't working so I was just using this other method to see if it was something with the way I was setting it up. Will be using that tool though.


Make sure to set the "inclusion" properties.  For a reason I cannot fathom, the default for the upper limit is always "non-inclusive" ("Clear" diamond.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 12
(154 Views)

I did notice this when reading the extra help about it. Thanks for this!

0 Kudos
Message 6 of 12
(148 Views)

@billko wrote:

@LearningLabVIEW wrote:

Thanks for this. I had this originally but it wasn't working so I was just using this other method to see if it was something with the way I was setting it up. Will be using that tool though.


Make sure to set the "inclusion" properties.  For a reason I cannot fathom, the default for the upper limit is always "non-inclusive" ("Clear" diamond.)


FYI, the "non-inclusive" coercion doesn't really work. For example, if your min and max values are 0 and 10 and you give it a value of 10 with the upper limit as non-inclusive, In Range? will return False, but coerced(x) will still return 10, despite it not being in range. The documentation is clear on this, but I would have expected coerced(x) to always give me a value that is within the range. It turns out that In Range? respects the inclusivity boxes, but coerced(x) does not.

 

coerce.png

 

I can hazard a guess on the non-inclusive default state. In a more general question of "in which set of values does my input belong", you have to make the decision of inclusivity at borders. For example, finding a given pixel in a grid of pixels means you have to decide if a pixel on a border belongs to the set of pixels to the left or to the right. In that type of comparison, it wouldn't make sense to be fully inclusive. Multiple comparisons would show a pixel as belonging to both sets of area. (In fact, the pixel searching tools do behave this way, so despite it being non-intuitive it's at least consistent).

 

In other words, it doesn't really make sense for a single comparison, but if you're doing multiple comparisons you DO need a consistent inclusive/non-inclusive pattern:

BertMcMahan_0-1632413895441.png

 

Honestly though I find myself using it in Inclusive mode about 99.99% of the time, so I'd prefer it to be default inclusive, but I can at least guess at why the original designer set it this way.

 

And to get back to the OP's question, this function does accept arrays as an input and will output a boolean array as an output:

 

coerce.png

 

 

Message 7 of 12
(146 Views)

@BertMcMahan wrote:

@billko wrote:

@LearningLabVIEW wrote:

Thanks for this. I had this originally but it wasn't working so I was just using this other method to see if it was something with the way I was setting it up. Will be using that tool though.


Make sure to set the "inclusion" properties.  For a reason I cannot fathom, the default for the upper limit is always "non-inclusive" ("Clear" diamond.)


<snip>

BertMcMahan_0-1632413895441.png

 

Honestly though I find myself using it in Inclusive mode about 99.99% of the time, so I'd prefer it to be default inclusive, but I can at least guess at why the original designer set it this way.

 

<snip>

 

 


I guessed at that, too, and for the same reason.  I couldn't fathom why this would be the default, though.  I'd prefer default inclusive also.  I wonder who they asked that said, "I almost always use them to compare the same value(s) over multiple ranges."?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 12
(138 Views)

Hi,

 

As you mentioned you would expect the function to return something within range, How can it return some arbitrary values?(or if should have an input field for default which is within the range). It is coercing if not in range as it should right.

And regarding inclusivity yes it should have been the default selection or the function name itself should be something like "within limits?"

bharath_p
LV2020
0 Kudos
Message 9 of 12
(90 Views)

There are many reasons for the function to be like it is.

 

The default of not including the upper limit is for mathematical reason quite correct. That statistics don't always seem to favor what we flawed humans consider common sense is another story, but there are good reasons for this.

 

Yes I also usually use this function with both limits included, except for floating point values where I usually don't want that value included.

 

And if you exclude one of the ends you don't need to use different constants if you stack two of those nodes to get two consecutive ranges. If both limits are included you could get values that belong to both ranges.

 

As to coerced returning the limit despite it being excluded, that is very logical for floating points values. What is the logically correct next smaller value to return in that case? The Limit - Machine Epsilon? Or the Limit - 1% of it? Or something totally different? The easiest is just to coerce the range simply always to the limits and don't try to be smart about well or not subtracting/adding something if the according limit is excluded.

 

Most of these choices are not arbitrary but done after days and days of debating in the development team. And if an issue is controversial, the mathematical correct way almost always wins over the arbitrary human common sense.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 10 of 12
(81 Views)