LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

grab array by boolean

Is there a built in way to grab indices of an array based on a boolean array (of the same size) that indicates whether or not each index should be grabbed.  This is a relatively straight forward solution to code up each time I use it but creating a sub vi that does this seems only to be possible if I cast to variant, which seems inefficient.  More specifically the steps that this vi would accomplish are:

1) count the # of trues for preallocation

2) preallocate array based on input data type

3) loop over all booleans, if the element is true, replace the current index in the preallocated array with the actual element from the input data

4) increment the counter to keep the correct index

 

Again, this is relatively straight forward to code each time but the various possible input data types (numeric, classes, enumerated data types, etc) would require a variant input (I think), and subsequently an additional variant to data type conversion, which is slightly annoying, and also may impact performance on large arrays.  Thoughts?  Thanks.

0 Kudos
Message 1 of 2
(2,449 Views)

There is no built-in way to do this, unless you consider the Express VIs. But that's a whole other story. OpenG has a polymorphic VI to do this. The VI is not optimized for large arrays. If you do a search you will find that this question has come up before, and alternate methods have been suggested.

0 Kudos
Message 2 of 2
(2,444 Views)