# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to find index of last true value in Boolean array

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.

Message 1 of 9
(656 Views)

## Re: How to find index of last true value in Boolean array

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
(649 Views)

## Re: How to find index of last true value in Boolean array

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. )

Message 3 of 9
(637 Views)

## Re: How to find index of last true value in Boolean array

try this

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.

Message 4 of 9
(620 Views)
Solution
Accepted by topic author @ironman

## Re: How to find index of last true value in Boolean array

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

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Message 5 of 9
(614 Views)

## Re: How to find index of last true value in Boolean array

Yamaeda's suggestion:

Message 6 of 9
(588 Views)

## Re: How to find index of last true value in Boolean array

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.

Message 7 of 9
(585 Views)

## Re: How to find index of last true value in Boolean array

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.

Message 8 of 9
(583 Views)

## Re: How to find index of last true value in Boolean array

@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
Message 9 of 9
(433 Views)