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
Removing specific elements in an array [message #94531] Tue, 27 June 2017 13:17 Go to previous message
thtran296 is currently offline  thtran296
Messages: 8
Registered: June 2017
Junior Member
Hello everybody,
So I have an array that looks like this:
x = [4,5,17,18,30,38,50,51,70]

The goal is to get rid of the element that is only 1 unit larger than the previous one.
The ideal output should look like:
x = [4,17,30,38,50,70] (since 5,18, and 51 are deleted)

I have tried all sorts of loops but it is not working. Here's my own attempt.
y = [4,5,8,15,30,31,45,70]
y2 = [y,0]
for i = 0,6 do begin
if y2(i) ne 0 then begin
if y2(i+1) - y2(i) le 1 then begin
remove, i, y
endif
endif
endfor

Please help. I appreciate it.
[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 09:09:16 PDT 2025

Total time taken to generate the page: 0.00432 seconds