LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to find index of last true value in Boolean array

Solved!
Go to solution

Please find the VI and images,

 

I want to know the index of the last true value of the boolean array. Please let me know what mistake im making. This index required for the case structure to display notifications.

 

The array has 64 elements. For loop N has 63, in my case the last (64 element) is true, but it is not showing as required.

 

Sometimes elements 64 go off and 60/61 becomes ON, so last element 61/62 should show.

 

ironman_0-1670315916797.png

ironman_1-1670315931955.png

 

0 Kudos
Message 1 of 9
(5,511 Views)

You answered it yourself, you have 64 elements but only look up to 63rd.

The index value goes from 0 to 63, but the N value needs to be 64.

 

EDIT:

Looked at your code and you also have it hooked up wrong. Looping through the array 63 times, but Search array function returns -1 once it hits the last element that fits.

Message 2 of 9
(5,504 Views)

Hi,

 

Thank you for the answer. However i am not getting the 64 element as shown in figure. Can you please check if you have labview with you. the picture attached for reference.

 

the idea is to get out of 64 elements, which one is true & that is last out of 64. (ex. elements 5, 10, 15, 50 are true, so index should show 50. )

 

 

0 Kudos
Message 3 of 9
(5,492 Views)

try this

 

AeroSoul_0-1670319072456.png

 

The mistake you made was looping through all elements, even after you've already found the last value, thus it returned -1. You should stop searching once you find -1, so while loop would be more appropriate.

 

0 Kudos
Message 4 of 9
(5,475 Views)
Solution
Accepted by topic author @ironman

The last True is the 1st True on a reversed array ...

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 9
(5,469 Views)

Yamaeda's suggestion:

 

AeroSoul_0-1670321871073.png

 

Message 6 of 9
(5,443 Views)

Hi,

 

Thank you for this, I tried this but still same result. this solution would have worked for me if i am stopping while loop, however i cant stop the while loop as some other system readings are being monitored. Yamaeda solution worked as required. 

 

Thank you all for all the inputs. 

0 Kudos
Message 7 of 9
(5,440 Views)

Thank you,

 

I tried this method, it works as needed. 

 

Only thing i have to re type or copy paste the strings in case selector in reversed order. This I will do. Thank you.

 

I assume there is no way to get the index without reversing array. Also numeric received converted to back same.  

 

 

0 Kudos
Message 8 of 9
(5,438 Views)
@ironman wrote:

I tried this method, it works as needed. 


I assume you are referring to AeroSoul post about Yamaeda's solution.

 

 


Only thing i have to re type or copy paste the strings in case selector in reversed order. This I will do. Thank you.

 


There are no strings or case selectors in your code or AeroSoul's code. What case selector are you talking about?

 


I assume there is no way to get the index without reversing array.


Yes, you can find the index without reversing the array. It would be slower and more complex.

 

 


Also numeric received converted to back same.  

 


Not sure what you are trying to say here. I assume the meaning of this was lost in translation.

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 9 of 9
(5,288 Views)