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
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.
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.
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).
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).