Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search and Erase Element from Array

0 views
Skip to first unread message

FightOnSCTrojan

unread,
Aug 15, 2008, 3:10:05 PM8/15/08
to
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/ni/170/349694/1/Sample.gif

altenbach

unread,
Aug 15, 2008, 3:40:19 PM8/15/08
to
~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.&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/ni/170/349709/1/removeBadStuff.gif


RemoveBadStuff1D.vi:
http://forums.ni.com/ni/attachments/ni/170/349709/2/RemoveBadStuff1D.vi

FightOnSCTrojan

unread,
Aug 15, 2008, 5:40:20 PM8/15/08
to
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;

altenbach

unread,
Aug 15, 2008, 6:10:06 PM8/15/08
to
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 :D).
FightOnSCTrojan wrote:

&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

0 new messages