05-29-2012 10:46 AM
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
05-29-2012 10:54 AM
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.
05-29-2012 11:26 AM
right now i just got the indices of 1's using while loop but i cannot find the indices of each 1's series
05-29-2012 12:03 PM - edited 05-29-2012 12:04 PM
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.
05-29-2012 01:33 PM
05-29-2012 01:57 PM
05-29-2012 02:08 PM
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.
05-29-2012 02:09 PM
@GerdW wrote:
Hi,
two more ideas:
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.
05-29-2012 03:41 PM
Ok, I know this is already solved, but I wanted to have fun.
A bit more obscure, but smaller.
05-29-2012 03:54 PM
@JW-L3CE wrote:
Ok, I know this is already solved, but I wanted to have fun.
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.