LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find longest sequence of equal values in array

Solved!
Go to solution

Hi,

 

I got an array with booleans, something like this

 

[TTFFFFFFFFFFFFTTFFTTT]

 

and I need to find the longest window were the array elements is equal, in the example above I want to find index 2 and length 12 for the longest window of F and index 18, length 3 for T. Anyone have an idé how I can do this?

 

 

0 Kudos
Message 1 of 5
(2,915 Views)
Solution
Accepted by Tudor

Hello Tudor,

 

There is so far I know no ready function in labview to do what you want. However this does not seem really hard to do.

 

You can link your table to a for loop and compare at each iteration the current boolean value to the previous one. If both are true, for example, you can increment a counter until one is true and the other false. Then you can save the length in a separate shift register if this length is longer than the preexisting one (initialize with 0). 

 

About the index, you can save the count terminal of the foor loop in a shift register when the value N-1 of your array is different than the value N,  At the next difference, if the length is the longer one, you save this count minus one in another register.

 

I hipe this helps you.

 

Regards 

______________
Florian Abry
Inside Sales Engineer, NI Germany
0 Kudos
Message 2 of 5
(2,907 Views)

This is maybe a bit clunky, but it gets the job done.

0 Kudos
Message 3 of 5
(2,878 Views)

I was more seing something with Case Structures but that was basically what I ment. I'm glad it is working for you. Smiley Happy

 

Regards 

______________
Florian Abry
Inside Sales Engineer, NI Germany
0 Kudos
Message 4 of 5
(2,874 Views)

I try to avoid case structures because they hide half the code from you at any given time.  I prefer to be able to see the whole VI at one glance.

0 Kudos
Message 5 of 5
(2,867 Views)