LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search 1D array indices problem


@crossrulz wrote:

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


Good point, I should explain for the OP.

 

It works by subtracting the current value from the previous value.

If you get a 0->1 transition, the subtraction results in a 1 and the current index is added (the "1" case).

If you get a 1->0 transition, the subtraction results in a -1 and the previous index is added (the "-1" case).

 

The last 0 is added to the array so that you can catch a 1 at the end of the array. If the last element is a 1, it will reach the end and subtract 0-1, get a "-1" result, and report the previous index (the REAL last index, not the added one)

The shift register is initialized to 0 so you can catch 1's at the start of the array. This would subtract 1-0 and get a "1" case.

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

@JW-L3CE wrote:

@crossrulz wrote:

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


Good point, I should explain for the OP.

 

It works by subtracting the current value from the previous value.

If you get a 0->1 transition, the subtraction results in a 1 and the current index is added (the "1" case).

If you get a 1->0 transition, the subtraction results in a -1 and the previous index is added (the "-1" case).

 

The last 0 is added to the array so that you can catch a 1 at the end of the array. If the last element is a 1, it will reach the end and subtract 0-1, get a "-1" result, and report the previous index (the REAL last index, not the added one)

The shift register is initialized to 0 so you can catch 1's at the start of the array. This would subtract 1-0 and get a "1" case.


There is a small (minor) issue with this, if you have a single 1 its index will be in the output twice (for the 0-1 and 1-0 transitions). Note that it migt be ok, it depend on what the OP wants.

 

Ben64

Message 12 of 15
(691 Views)

@ben64 wrote:

There is a small (minor) issue with this, if you have a single 1 its index will be in the output twice (for the 0-1 and 1-0 transitions). Note that it migt be ok, it depend on what the OP wants.

 

Ben64


Wow. Good eye. Kudos

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

Thanks all of you!!! that's very helpful!!!

 

Crossrulz .. now i'm trying to follow your solution , i've already subtracted the indices of o's by 1 

could you give me the suggest after that about how to add the last column of index to array

0 Kudos
Message 14 of 15
(667 Views)

The simple way is to append a 0 to the array before running through the loop.  This way you will see a transition from 1 to 0 (grab the previous index) or 0 to 0 (which you don't care about).


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 15 of 15
(647 Views)