LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Comparison Search

Solved!
Go to solution

Is there a method of searching an array for the first element which is less than a set number? - Like the Search Array function but with comparison instead of equals?

 

Thanks

0 Kudos
Message 1 of 4
(2,835 Views)
Solution
Accepted by topic author bbentelin

I don't think there's a direct way.

One simple option: do your comparison first (you can compare an array to a scalar), this will result in a boolean array. Then search for "True" in the boolean array.

 

Message 2 of 4
(2,824 Views)
I like that, thanks for the reply.
0 Kudos
Message 3 of 4
(2,822 Views)

If you have a large dataset, you should be a little careful.  Doing the comparison and then searching guarantees that you will operate on every element of the array and will also create a new one.  In this case just use a for loop with the conditional terminal set to stop when the condition is met.  This way you don't have a new buffer allocation, and you short-circuit the operation when you find the answer.  Be sure to check if you reached the end of the array (your loop will stop with a value of False for the last comparison).

 

All that said, I use the previous suggestion 95% of the time.

0 Kudos
Message 4 of 4
(2,794 Views)