LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What's the simplest way to reject zeros when auto indexing numbers in loop?

Hello

 

I have a kind of dummy question about rejecting zeros or negative numbers. I am reading live data in a loop over and over again and I need to save them for future processing. The way I am doing is just to auto index them and spit out at the end of loop. However there are zeros and negative values in the live data which i don't want. 

 

My question is, what is the simplest way to get rid of those zeros before even indexing them? I know i can handle them afterward in array manipulation (search for zeros/NaN etc), but I  hope I can reject them prior to save them. I know there gotta be some tricks. Can any of you help me?

 

Thanks

 

Harry

0 Kudos
Message 1 of 19
(3,699 Views)

If you are getting the points in the loop one at a time, you can check each value and feed the good ones into a queue and the have the other end of the queue, in a separate loop, auto index there.

Randall Pursley
Message 2 of 19
(3,696 Views)

Only add the point to the array if you want to keep it, instead of auto indexing.  Using Replace Array Subset instead of Build Array is more efficient.

array.png

Here, if the value is >.5, I add it to the array.  After the loop, I take the subset of the array with the good data in it.

--
Tim Elsey
Certified LabVIEW Architect
Message 3 of 19
(3,688 Views)

Depending on your use case, you could potentially get away with a "in range and coerce". This assumes that you don't absolutely need to minimize the array size and also assumes that you are guarding against doing math on a negative or 0 number, but doing the same math on for example 1 is safe.... so very specialized case where you could use this, but on the other hand it is very simple to implement and you can wire a constant "1" to the low range and "inf" to upper range and wire the array to the input... (not sure if this is faster than doing the "in range and coerce" inside the for-loop on each element individually or on the array output...) 

QFang
-------------
CLD LabVIEW 7.1 to 2016
Message 4 of 19
(3,683 Views)

Tim, thanks! I'll give it a try.

 

 

 

0 Kudos
Message 5 of 19
(3,669 Views)

QFang, thanks for your reply. I just don't want the zeors to be saved in my array at all.

 

0 Kudos
Message 6 of 19
(3,665 Views)

Tim,

 

I tried your suggestion. It turns out that, because of the initialization of array (with zeros), the final array will have zeros at those elements that are not been replaced, so I have to remove them once again. Any fix?

 

Also the array operation slows down the data collection quite a bit. I am working with signals come in ~500KHz, so any additional operation in the data collection loop slows down the read. Do you see any way around it?

 

Thanks

 

Harry

0 Kudos
Message 7 of 19
(3,644 Views)

@Harry.W wrote:

Tim,

 

I tried your suggestion. It turns out that, because of the initialization of array (with zeros), the final array will have zeros at those elements that are not been replaced, so I have to remove them once again. Any fix?

 
Also the array operation slows down the data collection quite a bit. I am working with signals come in ~500KHz, so any additional operation in the data collection loop slows down the read. Do you see any way around it?



You must have forgot the Array Subset after the loop. 

 

As for slowing down your acquisition, you may have to resort to filtering the array after the data is acquired.  I would not expect a simple Replace array subset to slow the loop down that much though.  Anyway, if you index the comparisons you can use OpenG's Conditional Auto-Indexing tunnel as a single VI approach to the filtering.  Of course, this requires the OpenG toolkit.

Array.png

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 8 of 19
(3,642 Views)

Pre-initializing the array, the replacing elements should be very fast and efficient.

If (after you add the array subset outside the loop to get only the "real" values you want) it is still too slow, you may want to consider making a (queue driven) producer consumer and have the producer just send raw data as it becomes available and have the consumer do the post processing. this might allow you to acomplish your goal, especially if you are running on a dual (or greater) core computer.

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 9 of 19
(3,634 Views)

dear sir

i  want to remove all those rows containing zeroes in the arrays D1 and D2 before auto-indexing.what i mean to say is that i don't want to pass zeroes to the array.i am attaching the vi(in 2010 version).please suggest.

0 Kudos
Message 10 of 19
(3,599 Views)