LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

Search array for 0 or 1 throughout

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.

Message 1 of 6
(2,502 Views)

Re: Search array for 0 or 1 throughout

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

Message 2 of 6
(2,485 Views)

Re: Search array for 0 or 1 throughout

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)

Message 3 of 6
(2,475 Views)

Re: Search array for 0 or 1 throughout

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.

Message 4 of 6
(2,290 Views)
Solution
Accepted by topic author MattStock1984

Re: Search array for 0 or 1 throughout

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).
Message 5 of 6
(2,285 Views)

Re: Search array for 0 or 1 throughout

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

Message 6 of 6
(2,250 Views)