LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching 2D Array with for Boolean 0

I have a boolean array that I would like to search for the first "0" in. Does anyone have a good example for me. I know this has got to be easy, but i am new to Labview. Any help is greatly appreciated.
Mike
0 Kudos
Message 1 of 8
(4,132 Views)
If your array is a 1D array: use the function 'Search 1D array' located in the function pallette-->Array-->Search 1D array
0 Kudos
Message 2 of 8
(4,130 Views)
it is a 2D array, is there an easy way to do this?
0 Kudos
Message 3 of 8
(4,130 Views)
First you need to define what you mean by the "first 0." Do you check rows first or columns?

You can put the search 1D array inside a while loop with indexing enabled on the tunnel where the array enters the loop.

Or use two nested loops. Stop both loops when a 0 is found. The iteration counters of the loops are the indexes of the first zero. If it is possible that no zero exists in the array, put in a test to stop the loops when all the elements have been tested. Otherwise the loops will run forever.

This technique can be extended to arrays of any dimension.

Lynn
Message 4 of 8
(4,130 Views)
Look at attached example. It will search each column in row 0 first. If you want to search each row in column 0 first, you can transpose the input array.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 8
(4,130 Views)
Boolean arrays don't have "0", just true of false 😉

Anyway, I would probably just reshape the 2D array to a 1D array, use search 1D array, then calculate the original 2D index. I have attached a simple example (LabVIEW 7.1).
0 Kudos
Message 6 of 8
(4,131 Views)
Sorry, I probably swapped the row and column output labels by accident in the above example. Still, you should get the general idea 😉
0 Kudos
Message 7 of 8
(4,123 Views)
I spent a minute to clean up my hurried example above to correctly deal with the special case where the 2D array does not contain any "False". I also saved it in LabVIEW 7.0 for better compatibility.

Remember, reshaping an array is computationally very cheap because it does not physically move the data in memory (See the online help for more details).
0 Kudos
Message 8 of 8
(4,109 Views)