LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search array for 0 or 1 throughout

Solved!
Go to solution

Hello. I have one column of data with 530,000 rows. The only values are either a 0 or a 1 (1 represents the occurence of an event; 0 does not). I'd like to be able to determine the amount of 0s in between each consecutive occurence of 1 throughout the entire array. For example, I'd like to be able to determine the number of zeros (i.e., rows) in between the first and second 1, the second and third 1, the third and fourth 1, etc, then determine the mean. Using the Search 1D array function makes it pretty easy to do for a few occurances, but I'm having trouble figuring out how to search through all 530,000 rows. Thank you in advance for your help.

 

Capture.JPG

 

 

0 Kudos
Message 1 of 6
(2,536 Views)

Here is one approch . I am not sure if this is best  one.

 

Download All
0 Kudos
Message 2 of 6
(2,519 Views)

Here's an alternative version that processes it as string. 😄

 

Of course it takes a simulated 1D array of U8 (using the bernoulli distribution tool), but you should be able to easily prep your own array to conform to that and process it the same way. (e.g. get the column using index array and convert to U8)

 

(It would be more efficient to sum the sizes in a shift register and divide by the size at the end, but this should get you started)

 

 

 

Download All
Message 3 of 6
(2,509 Views)

Hi altenbach,

 

Forgive my ignorance, but implementing a Read from Spreadsheet with an Indexed Array leads to a coercion dot on the U8 function, and my output for the mean is the array size (i.e., string length). Can you tell me where I'm going wrong? I've attached an example data file I am using.

Download All
0 Kudos
Message 4 of 6
(2,324 Views)
Solution
Accepted by MattStock1984

MattStock1984 wrote:

Forgive my ignorance, but implementing a Read from Spreadsheet with an Indexed Array leads to a coercion dot on the U8 function, and my output for the mean is the array size (i.e., string length). Can you tell me where I'm going wrong? I've attached an example data file I am using.


  • Nothing wrong with the coercion. (However, I told you to convert to U8 in my instructions to prep your array)
  • You did not add 48 as in my code. Why not? (If you don't add 48, your delimiter needs to be set as a special non-printable character (x01), making the code hard to read. Also, if you don't add 48, the character "1" (ASCII 49!) will never occur and you get the full lenth as expected).
0 Kudos
Message 5 of 6
(2,319 Views)

I believe I understand now. Thank you for your help.

0 Kudos
Message 6 of 6
(2,284 Views)