LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
altenbach

Allow boolean arrays as input for "Array Min & Max"

Status: New

The Array Max & Min function is quite versatile, but for some reason it does not accept boolean arrays.

 

This restriction make no sense at all. Since we can easily sort boolean arrays, this function should work too!

 

It would come in handy for example if looking for the position of a single TRUE in a 2D array (search only works for 1D arrays!). Array min & max would simply return the index pair of the first TRUE found. As a workaround, we currently need to insert a "boolean to 0,1" to get the same effect. This seems unecessary.

18 Comments
AristosQueue (NI)
NI Employee (retired)

And Array Elements and Or Array Elements handles this more efficiently, and, frankly, when reading a diagram, I'd rather see the And or Or prim than the Min/Max prim for a boolean array -- it's clearer what operation is being performed.

 

OrArrayElements.png

altenbach
Knight of NI

> And Array Elements and Or Array Elements handles this more efficiently...

 

This is not a substitute, because it does not give the index position of the boolean. Imagine you have a 8x8 array of buttons and associated event structure and want to find out which one got pressed.

 

Same for a control of a 2D array of numbers. Simply do a "!=" on the old and new value, then find the TRUE in the resulting 2D boolean array to get the indices of the changed element.

 

Frankly, I use the workaround (with the boolean to 0,1 inserted) all the time.

.

Message Edited by altenbach on 12-03-2009 11:40 AM
AristosQueue (NI)
NI Employee (retired)
Ok, I can see how this is a good idea if that's useful to you... I've never had reason to know where the bool was, only if it existed.
Darin.K
Trusted Enthusiast
Since booleans are no longer stored as bits in an array, how will this work?  Will you get the first value, or whichever random value had the highest random bit pattern.  If you don't go out of your way to obfuscate code, does a boolean array naturally end up 0/1?
altenbach
Knight of NI

Any boolean you generate within LabVIEW will be normalized, I guess.

 

(It might be interesting to see how sorting such a boolean array (with random patterns in each element) would be handled. You can easily make the experiment by sorting a array where each element is a cluster of a boolean and a unique identifier). 😉

 

If course you can always safeguard with some Rube-Goldbergian "equal true" or similar if you worry about that. 😉

Knight of NI
I have to disagree with the need to do this. The case where this would come in handy is a very unique one, and while I can see that it would be useful in this specific case, I fail to see the need to change the function to support this fringe case, especially since, as you noted, the simple workaround is to use the Boolean to 0,1 function.
altenbach
Knight of NI

> I have to disagree with the need to do this

 

LabVIEW prides itself of function polymorphism, but there are these nagging little holes that give you a broken wire for no obvious reason at all. Sure there are workarounds, but the beginner programmer might construct a horrible Rube Goldberg style workaround, full of duct tape and bailing wire.

 

We can sort boolean arrays so there is a clear order between TRUE and FALSE ---> there is a MAX and a MIN and the function should return it.

 

Note that Array Min&Max even works for string arrays, where it outputs the lexically sorted first and last array element. (Hey, I did not know that, could be useful sometimes!).

 

Not allowing boolean array inputs is an unnatural exception and should be fixed. 😉

 

A similar case is described in this suggestion (which did not get much attention either) 😞

Knight of NI
Well, your passion for this is clear, but I'm simply not convinced. I don't see not including Boolean arrays as an "unnatural exception". It simply makes no sense to me conceptually why I would want to search for the min/max of a Boolean array. Of course, I'm not the one you need to convince, and I encourage you to continue your gusto for this.  😉
altenbach
Knight of NI

Ok, let's look at the following code:

 

Explain why "array min&max" works perferctly well on an array containing a cluster of a single boolean while it rejects a nearly similar, but flat boolean array? Why this arbitrary exception??? 🙂 I don't like exceptions!

 

MaxBooleanArray.png

altenbach
Knight of NI

Here is an example application for this. Note that it only works because we have a cluster in the 3D array. If we have any plain 3D array, we would need to insert a "boolean to 0,1" after the comparison. Why? 😉