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

I want to be able to find the total number of True's before and after a false Boolean. So far I have the indices for them at each iteration.

for example, if I have Boolean element 3 off and 0,1,2 is on and also 6,7,8 is on. I want it to tell me that before 3 there are a total of 3 Boolean on and after there is 3 Boolean off. Do the same check each time it finds a Boolean that is off.

my code is attached, please help

0 Kudos
Message 1 of 33
(4,270 Views)

Hi. You're version of LabVIEW is too up to date for me to open the VI, but this is how I would go about doing this. It's probably not the most efficient way, but it works for me.

 

Wire the Boolean array to a for loop and use auto indexing for the input.

Within the for loop:

     Use the array search function to search for FALSE within the for loop.

     If a FALSE value is found, then save the "i" value an auto-indexing tunnel.

     If a TRUE value is found, then save the value "-1" to an auto-indexing tunnel.

Pipe the auto indexing output tunnel from the for loop to the shift register of a while loop.

Within the while loop:

     Wire an array search function to search for a "-1" value.

     Wire the index to a "greater than or equals to zero" function.

     Wire the result of the greater than or equals to function to the while loop conditional.

     Set the while loop conditional to run if true.

     Wire the result of the greater than or equals to function to a conditional.

     Within the TRUE condition of the conditional structure, place a remove index function. Pipe the index found by the search function to the remove function. Pipe the array from the shift register to the input of the remove index function. Pipe the output of the remove index function into the shift register at the end of the while loop.

     Within the FALSE condition of the conditional structure, just run the array from one side to the other.

Finally, at the output of the while loop, you will have an array of the number of TRUE values that are between FALSE values.

 

-edit-

This will only work if the array is built like this: [T,T,T,T,F]

0 Kudos
Message 2 of 33
(4,250 Views)

Does it only count the number of trues up until the next false?

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 33
(4,243 Views)

Ah. You're right. You'll have to wire a negative offset to get the other ones. Shouldn't be too difficult to figure out.

0 Kudos
Message 4 of 33
(4,241 Views)

Hm. Actually, this is a bit difficult. Can you explain what you have going on currently or take a snap shot? I only have LabVIEW 2015 and it won't open your 2016 file.

0 Kudos
Message 5 of 33
(4,238 Views)

Maybe you could add a FALSE value to the end of your Boolean array. Then, split the array into separate arrays after each FALSE.

For instance:

Boolean array is [F,T,T,T,F,F,T,F,T,T]

Concatenate a FALSE value to the end.

Boolean array is [F,T,T,T,F,F,T,F,T,T,F]

Split the array after each FALSE value.

Boolean arrays are [F], [T,T,T,F], [F], [T,F], [T,T,F]

Feed each array into the function I had described earlier without the while loop. Result should be: 0,3,0,1,2

0 Kudos
Message 6 of 33
(4,227 Views)

@aputman yes It would count the true up to the next false..

0 Kudos
Message 7 of 33
(4,218 Views)

My question was for the OP.  Do you want a count of all the trues in the array before and after each false, or only the ones up to the next false?

 

For example,

TTTFTTTFTTFT

Should the first F return (3,3) or (3,6)?

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 8 of 33
(4,213 Views)

Here's a snippet of what it looks like

 

0 Kudos
Message 9 of 33
(4,211 Views)

Yes  it would count the trues up until the next false.

so if I have True True False True false True true

I should get   for the 1st false: 2, 1

                                  2nd false: 1, 2

0 Kudos
Message 10 of 33
(4,207 Views)