LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding the total number of Trues before and after each false in a boolean array

Solved!
Go to solution

Hello,

   Thanks for all your help so far and I apologize for misleading you.  I had no intention to do so because I wouldn't benefit from it.

    As I look at the code, I get how the loop index each iteration values when the 2nd conditional terminal is false to get the false index values.

  I get how when the 1st conditional terminal is false, it takes the old val from shift register + 1 and index those values as all the true before a false.

  Same goes for the values of "true after a false" only you subtract all the values of "True after a false'' from all values of "True before a false".

now to modify the code to make it stop counting when it reaches a false, I am clueless. I spend some good time on it. Please help if you can

0 Kudos
Message 21 of 33
(1,574 Views)

Well, one way to do it, the number of trues after a false will also be the number of trues before a false, if you shift the array by -1.  But then you need to deal with the edge cases.

aputman
0 Kudos
Message 22 of 33
(1,565 Views)

@aputman,

 wouldn't that only shift my result by -1?.... that's without account for edge...

 

0 Kudos
Message 23 of 33
(1,564 Views)

@ritch_by_nature wrote:

 

now to modify the code to make it stop counting when it reaches a false, I am clueless. I spend some good time on it. Please help if you can


This is a good exercise, so here is a partial solution that shows how to count only the near TRUEs before the FALSE. You simply need to reset the counter and keep its most recent value as long as the boolean is FALSE. (I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).

 

It would be trivial to add the "after" count. The most obvious solution would be to reverse the boolean array and then reverse the result, but there are plenty of other ways. Try it!

 

 

Download All
0 Kudos
Message 24 of 33
(1,559 Views)

@ritch_by_nature wrote:

@aputman,

 wouldn't that only shift my result by -1?.... that's without account for edge...


Only if there are never more than one FALSE in a row. For example, if the array is:

 

T-T-F-T-T-T-F-F-F-F-F-T

The before's are: 23333

The after's are: 31111

 

Clearly not just a shift. 😄

0 Kudos
Message 25 of 33
(1,555 Views)

So this is what I meant by shift the array.  I'm taking a subset of the array starting at index 1.  The only problem with this is that the last value in your results array will be wrong, if the last value in the boolean array is a true. 

Example_VI_BD.png

aputman
0 Kudos
Message 26 of 33
(1,553 Views)

@aputman wrote:

So this is what I meant by shift the array.


It depends on the expected behavior of there are multiple FALSE in a row. Should e.g. the second FALSE return zero (because there are no adjacent TRUEs before) or should it return the count of the closest stretch of TRUEs below.

0 Kudos
Message 27 of 33
(1,550 Views)

 (I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).

Yes I do.. if there is TTFFFFFFFFT.  The first false would be 2, 1...same for the others consecutives falses.

 

0 Kudos
Message 28 of 33
(1,546 Views)

@ritch_by_nature wrote:

 (I assume that you want to keep returning the same value even if there are multiple FALSEs in a row).

Yes I do.. if there is TTFFFFFFFFT.  The first false would be 2, 1...same for the others consecutives falses.

 


Yes, that's what my code does. Follow my suggestion and you also get the "after" counts. 😄

0 Kudos
Message 29 of 33
(1,539 Views)

Has this been solved? There's a lot of correspondence. It's kind of difficult to follow.

0 Kudos
Message 30 of 33
(1,528 Views)