# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to find three consecutive non zero number from an array

Hi, I'm trying do a very simple program in labview, but I'm stuck.

I have an array of u8 in a sequence of zeros and non zeros, but I'm interested on finding the first three consecutive non zeros on the array.

ie.  0 0 0 0 1 0 0 2 3 0 0 2 3 3 0 0 ...

the output would be 2 3 3

Thank you Gustavo R.

Message 1 of 9
(3,317 Views)
Solution
Accepted by topic author GustavoRamirez

## Re: How to find three consecutive non zero number from an array

Run the array into a for loop or while loop with the array auto indexed at the input to the loop. Increment a counter in a shift register when the array element is non-zero and reset it to zero when the array element is zero.  When the counter is >2 you have three consecutive non-zero elements.

Lynn

Message 2 of 9
(3,313 Views)

## Re: How to find three consecutive non zero number from an array

Definitively you rock. That was fast and was right.

Thank you very much, I was starting to bang my head with the monitor.  🙂

This is the final code, simple and direct.

Thank you!!!

Gustavo

Message 3 of 9
(3,305 Views)

## Re: How to find three consecutive non zero number from an array

I'm bored at work so I wrote a more terse version.

Message Edited by elset191 on 06-10-2009 01:05 PM
--
Tim Elsey
Certified LabVIEW Architect
Message 4 of 9
(3,297 Views)

## Re: How to find three consecutive non zero number from an array

GustavoRamirez wrote:

the output would be 2 3 3

None of the examples given above output the specified array of three elements. You need to also deal with the case where no match is found. Your while loops will never finish!

Here's another way to do this.

Message Edited by altenbach on 06-10-2009 11:21 AM

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 5 of 9
(3,290 Views)

## Re: How to find three consecutive non zero number from an array

That works also, the code I did after finding the trhee consecutive numbers got the index number and returned the substring of the original array at index minus 2, but this last solution is by far more elegant.

Thank you

Gustavo

Message 6 of 9
(3,280 Views)

## Re: How to find three consecutive non zero number from an array

touche
--
Tim Elsey
Certified LabVIEW Architect
Message 7 of 9
(3,279 Views)

## Re: How to find three consecutive non zero number from an array

Here's a version that does not use any loops. 😄

There are many other solutions, of course.

Note that the conversions operate "in place".

Message Edited by altenbach on 06-10-2009 12:59 PM

LabVIEW Champion. It all comes together in GCentral
What does "Engineering Redefined" mean??
Message 8 of 9
(3,257 Views)

## Re: How to find three consecutive non zero number from an array

Is there a regular expression for comparison operators?  I want to find three consecutive values less than a particular value.

Message 9 of 9
(2,634 Views)