LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find three consecutive non zero number from an array

Solved!
Go to solution

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,313 Views)
Solution
Accepted by topic author GustavoRamirez

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,309 Views)

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 

 

ProblemSolution.png 

Message 3 of 9
(3,301 Views)

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,293 Views)

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 GCentral
What does "Engineering Redefined" mean??
Download All
Message 5 of 9
(3,286 Views)

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 

0 Kudos
Message 6 of 9
(3,276 Views)
touche
--
Tim Elsey
Certified LabVIEW Architect
Message 7 of 9
(3,275 Views)

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 GCentral
What does "Engineering Redefined" mean??
Download All
Message 8 of 9
(3,253 Views)

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

0 Kudos
Message 9 of 9
(2,630 Views)