LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search and Erase Element from Array

I have an 1D array of N (approx 90K) elements. I am trying to get rid of all zeros and NaN in the array. What is the fastest way to do so? My solution has been search for array, delete element, repeat the process until the search comes up to be empty (index value =-1).

 

As always, your insights/tricks/inputs are much appreciated.

 

Best,


Santiago

Message Edited by FightOnSCTrojan on 08-15-2008 11:47 AM
0 Kudos
Message 1 of 17
(10,561 Views)

You never want to use "delete from array" in a loop, because every resizing operation forces a new copy of the array in memory. You should do everything "in place" and trim the excess at the end.

 

Do something like the bottom code in this VI. Simply adapt it to your requirements.

 

(Original discussion)

 

Please let us know if you have any questions.

Message 2 of 17
(10,549 Views)
What about NaN, +Inf and -Inf?  I think if you can type it in a numeric control you should also be able to type it in the Selector Label on the case statement. 
jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 3 of 17
(10,542 Views)

~jiggawax~ wrote:
What about NaN, +Inf and -Inf?  I think if you can type it in a numeric control you should also be able to type it in the Selector Label on the case statement. 

No, case selectors are integer, so NaN, Inf, etc. have no meaning.

 

Here's a quick example on what I would do. Be careful comparing NaN, for example of you ask NaN=NaN, the answer is false. You need to use the special primitive from the comparison palette.

 

Of course, since you are dealing with DBL, only true zeroes will get removed, so all caveats comparing floating point numbers still apply. If this is a concern, you need to deal with it with some extra code.

 

Message Edited by altenbach on 08-15-2008 12:41 PM
Download All
Message 4 of 17
(10,532 Views)

Altenbach....which tool/function did you use last on your example (outside the for loop, before connecting it to the indicator)?

Sorry...I am running LV 8.2...so I could not open the VI

0 Kudos
Message 5 of 17
(10,504 Views)
Nevermind....answer my own question...reshape array
0 Kudos
Message 6 of 17
(10,501 Views)

Altenbach:

 

As always…Thanks for your suggestion.

I tried to do some time study contrasting your proposed method and my original method.

The result….Altenbach (2ms), Santiago (6806ms).

Therefore he is 3000+ times better than me.

Rightfully so,

 

Santiago

 

p.s. Would you mind giving some thoughts about http://forums.ni.com/ni/board/message?board.id=170&thread.id=349480? Thanks!

 

0 Kudos
Message 7 of 17
(10,497 Views)

FightOnSCTrojan wrote:

The result….Altenbach (2ms), Santiago (6806ms).


Sounds about right. Your original method is only good if you need to remove very few elements (such as zero or one :D).


FightOnSCTrojan wrote:

p.s. Would you mind giving some thoughts about http://forums.ni.com/ni/board/message?board.id=170&thread.id=349480? Thanks!


 

 I would go with Karissa's "numeric" method if it is appropriate for your data. Going to strings and back is expensive.

 

Message Edited by altenbach on 08-15-2008 02:57 PM
0 Kudos
Message 8 of 17
(10,491 Views)

Can someone please tell me how to delete the zeros from an array. but only the beginning zeros and ending zeros. since i am gettting waveform data some zero in the middle of array should not be deleted. 

0 Kudos
Message 9 of 17
(9,772 Views)

(Please start a new thread instead of adding to a 2 year old discussions that is not very similar. Also please attach a real VI containing some default data instead of an image.)

 

Simply find the first and last nonzero element and then take the array subset of all data in-between.

 

ALso note that comparisons of DBL data with zero might cause problems.

 

0 Kudos
Message 10 of 17
(9,754 Views)