04-19-2017 03:51 PM
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
Solved! Go to Solution.
04-19-2017 04:24 PM - edited 04-19-2017 04:40 PM
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]
04-19-2017 04:32 PM
Does it only count the number of trues up until the next false?
04-19-2017 04:34 PM
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.
04-19-2017 04:39 PM
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.
04-19-2017 04:52 PM
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
04-19-2017 04:58 PM - edited 04-19-2017 05:11 PM
@aputman yes It would count the true up to the next false..
04-19-2017 05:01 PM
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)?
04-19-2017 05:05 PM - edited 04-19-2017 05:06 PM
Here's a snippet of what it looks like
04-19-2017 05:09 PM
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