comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Removing specific elements in an array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Removing specific elements in an array [message #94533 is a reply to message #94532] Tue, 27 June 2017 14:57 Go to previous message
gombgg is currently offline  gombgg
Messages: 7
Registered: November 2013
Junior Member
Mike beat me to it. My response is equivalent:

You shouldn't need loops.

You didn't define what you want to do with the first element, which has no predecessor. You also didn't specify whether your output array is allowed to have neighbouring elements that differ by one. (eg, what should happen if x=[5,10,11,11,11,20] ?)

So long as the last element isn't one less than the first element, this will work:

result=x[where((x-shift(x,1)) ne 1,/null)]

If you want to make sure the last element doesn't mess things up, this should work:

inds=where((x-shift(x,1)) ne 1,count)
if count eq 0 then result=x[0] else begin
if inds[0] ne 0 then inds=[0,inds] ;make sure the first element is included
result=x[inds]
endelse
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Linux installation problems..
Next Topic: Check numerical derivatives

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:05:51 PDT 2025

Total time taken to generate the page: 0.00394 seconds