LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search 1D array indices problem

Hello All

 

I'm trying do my project in labview, but I'm getting stuck

 

I have 1D array consists of series of 1 and 0 like this -->  1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1


but I'm interested on finding the indices of 1 which are only the start and end point of the series


for example: input is 1 1 1 0 0 0 1 1 1 1 0 0 1 1 1

 

the output should be 0 2 6 9 12 14

 

Thank you  

 


0 Kudos
Message 1 of 15
(3,757 Views)

Sounds like you need a for loop with a couple of shift registers.  One shift register should be used hold the previous value and another to keep the array indecies.  Compare the previous value to the current one, if they are different add the index to the array using the build array function.

 

What have you tried so far?  Give us some code and explain where you are stuck.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 15
(3,750 Views)

right now i just got the indices of 1's using while loop but i cannot find the indices of each 1's series

 


0 Kudos
Message 3 of 15
(3,729 Views)

I think the way you're searching is flawed.  Like I said earlier, I would look for changes in the array values and store those indices.  I was also playing with your original code and alternated what to search for (1 and 0).  Either solution should work.

 

I decided to build upon what you already had.  I used the remainder of (i+1)/2 to alternate between searching for 1 and 0.  I will admit that this is not a final solution (I can't just give you an answer).  You will need to account for when the new value is a 0 (subtract 1 from the index) and add the last index if it is a 1 and wasn't already included.

findindices1_BD.png


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 15
(3,711 Views)

Hi,

 

two more ideas:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 15
(3,686 Views)

And one more.

 

Ben64

 

Search Array Index.png

Message 6 of 15
(3,678 Views)

ben64,

  That's a great way to do it.  It removes the extra logic I needed in order to get the last element and the need to subtract the index for transitions to 0.  My only thing is that I would put the build array in a case structure to save some memory.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 15
(3,670 Views)

@GerdW wrote:

Hi,

 

two more ideas:

check.png


Gerd, you might be having a little too much fun with those Pt-by-Pt VIs....  In all seriousness, I really need to look at them.  They seem VERY useful.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 15
(3,666 Views)

Ok, I know this is already solved, but I wanted to have fun.

Find 1s.png

A bit more obscure, but smaller.

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 9 of 15
(3,648 Views)

@JW-L3CE wrote:

Ok, I know this is already solved, but I wanted to have fun.

Find 1s.png

A bit more obscure, but smaller.


Yeah, I can tell I've rubbed off on you at least a little bit.  That was my original train of thought.  I abandoned it however because I was trying to help the OP think through the problem.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 15
(3,643 Views)