Search and Erase Element from Array

This is a discussion on Search and Erase Element from Array within the labview forums in Programming Languages category; 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, SantiagoMessage Edited by FightOnSCTrojan on 08-15-2008 11:47 AM Sample.gif: http://forums.ni.com/ni/attachments/...4/1/Sample.gif...

Go Back   Application Development Forum > Programming Languages > labview

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-15-2008, 03:10 PM
FightOnSCTrojan
Guest
 
Default 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,
SantiagoMessage Edited by FightOnSCTrojan on 08-15-2008 11:47 AM


Sample.gif:
http://forums.ni.com/ni/attachments/...4/1/Sample.gif
Reply With Quote
  #2  
Old 08-15-2008, 03:40 PM
altenbach
Guest
 
Default Re: Search and Erase Element from Array

You never want to use &quot;delete from array&quot; in a loop, because every resizing operation forces a new copy of the array in memory. You should do everything &quot;in place&quot; and trim the excess at the end.&nbsp;Do&nbsp;something like the bottom code in <a href="http://forums.ni.com/ni/attachments/ni/170/116060/3/RemoveZeroes_1D.vi" target="_blank">this VI</a>. Simply adapt it to your requirements. &nbsp;(<a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&am p;message.id=116060#M116060" target="_blank">Original discussion</a>) &nbsp;Please let us know if you have any questions.
Reply With Quote
  #3  
Old 08-15-2008, 03:40 PM
~jiggawax~
Guest
 
Default Re: Search and Erase Element from Array

What about NaN, +Inf and -Inf?&nbsp; 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.&nbsp;
Reply With Quote
  #4  
Old 08-15-2008, 03:40 PM
altenbach
Guest
 
Default Re: Search and Erase Element from Array

~jiggawax~ wrote:
What about NaN, +Inf and -Inf?&nbsp; 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.&nbsp;
No, case selectors are integer, so NaN, Inf, etc. have no meaning.&nbsp;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.&nbsp;Of course, since you are dealing with DBL, oly true zeroes will get removed, so all caveats comparing floating point numbers still apply. If this is a concern, oyu need to deal with it with some extra code.&nbsp;<img src="http://forums.ni.com/ni/attachments/ni/170/349709/1/removeBadStuff.gif" border="0" width="610" height="304"> Message Edited by altenbach on 08-15-2008 12:39 PM


removeBadStuff.gif:
http://forums.ni.com/ni/attachments/...veBadStuff.gif


RemoveBadStuff1D.vi:
http://forums.ni.com/ni/attachments/...eBadStuff1D.vi
Reply With Quote
  #5  
Old 08-15-2008, 05:40 PM
FightOnSCTrojan
Guest
 
Default Re: Search and Erase Element from Array

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
Reply With Quote
  #6  
Old 08-15-2008, 05:40 PM
FightOnSCTrojan
Guest
 
Default Re: Search and Erase Element from Array

Nevermind....answer my own question...reshape array
Reply With Quote
  #7  
Old 08-15-2008, 05:40 PM
FightOnSCTrojan
Guest
 
Default Re: Search and Erase Element from Array

Altenbach: &nbsp;
As always&hellip;Thanks for your suggestion.
I tried to do some time study contrasting your proposed method and my original method.
The result&hellip;.Altenbach (2ms), Santiago (6806ms).
Therefore he is 3000+ times better than me.
Rightfully so,&nbsp;
Santiago
&nbsp;
p.s. Would you mind giving some thoughts about <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;thread.id=349480" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&amp;thread.id=349480</a>? Thanks!
&nbsp;
Reply With Quote
  #8  
Old 08-15-2008, 06:10 PM
altenbach
Guest
 
Default Re: Search and Erase Element from Array

FightOnSCTrojan wrote:

The result&hellip;.Altenbach (2ms), Santiago (6806ms).
Sounds about right. Your original&nbsp;method is only good if you need to remove very few elements (such as zero or one ).
FightOnSCTrojan wrote:

p.s. Would you mind giving some thoughts about <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;thread.id=349480" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&amp;thread.id=349480</a>? Thanks!
&nbsp;&nbsp;I would go with Karissa's &quot;numeric&quot; method if it is appropriate for your data. Going to strings and back is expensive.&nbsp;Message Edited by altenbach on 08-15-2008 02:57 PM
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:47 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.