LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Compare an array element with the previous and next element of a certain value

Hi I have an array of Boolean. I want to be able to turn some of them off but what I want to check for is if I set an element of I want to know the index of that element then I want to find the index of the element before it that is ON the one after it that is ON as well..

For example, If I turn array element 2 off and 1 is on and 12 is on. I want it to output that results first element off is 2, and then element ON before is 1 and after is 12. then Move on to the next element that is OFF.. So far that's what I have. I can't seem to move on past that. Please help me..see attached

0 Kudos
Message 1 of 6
(3,725 Views)

This where I am leading so far.... I still cant manage to get what I want...

0 Kudos
Message 2 of 6
(3,690 Views)

Something like this:

FindTRUEs.PNG

 

Please note to add a stop button with an appropriate event case to stop your VI is considered mandatory!

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 6
(3,683 Views)

Thanks for your reply. I am testing It but is there anything in the true case. Are the tunnels for case structure wired with default?

Update:

  I tested with default wiring and it doesn't seem to work. Would you post the snippet of your code instead. I am afraid I might make mistake duplicating it....

Attached is the answer I get testing it

0 Kudos
Message 4 of 6
(3,675 Views)

I found where I made a mistake in the delete array. It works fine now.

One more question, what if I want to count the number of consecutive ones before and after the one that is OFF.

for example if I turn off index 2 but 0 and 1 is on...it should give me the total number of 1 before 2 is 2... and same for the one after....

0 Kudos
Message 5 of 6
(3,636 Views)

You can implement a recursive search for TRUE which stops as soon as

a) a FALSE is found as next/previous value

b) the array has no elements left to search

 

I am not sure how well this scales performance wise. Another option might be to treat the boolean array as integer number and use bit masking to look for criteria like you mentioned...

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 6
(3,610 Views)