06-10-2009 12:23 PM
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.
Solved! Go to Solution.
06-10-2009 12:37 PM
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
06-10-2009 12:49 PM
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
06-10-2009 01:04 PM - edited 06-10-2009 01:05 PM
I'm bored at work so I wrote a more terse version.
06-10-2009 01:18 PM - edited 06-10-2009 01:21 PM
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.
06-10-2009 01:29 PM
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
06-10-2009 01:29 PM
06-10-2009 02:57 PM - edited 06-10-2009 02:59 PM
Here's a version that does not use any loops. 😄
There are many other solutions, of course.
Note that the conversions operate "in place".
07-27-2011 09:42 AM
Is there a regular expression for comparison operators? I want to find three consecutive values less than a particular value.