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

Home » Public Forums » archive » Re: Where and lists of regions
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: Where and lists of regions [message #41317 is a reply to message #41316] Mon, 11 October 2004 21:39 Go to previous messageGo to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 11 Oct 2004 14:47:23 +0200, Ben Panter wrote:

> Hi,
>
> I'm in the middle of trying to simplify a large body of code which I
> inherited a few years ago and have been mangling ever since. Among other
> things, I'd be interested in anyone's thoughts on simplfying the case
> statement I use (full code below). Basically I have a list of regions
> which I want to remove from a vector. At the moment I use CASE to call
> WHERE to remove the regions elements (case to choose how many where
> statements are required). This is fine for a few regions, but I'm sure
> there must be a neater way, as when I need 10 regions, or even 20, this
> code is going to look terrible...
>
> I've written a code with EXECUTE, but I may want to use VM in the future
> so I'd like to avoid it if possible.

How about:

flag=bytarr(n_elements(wave))
for i=0,n_regions-1 do $
flag+=wave gt reg[i,0] AND wave lt reg[i,1]
return, where(~flag)

There are other methods for removing more complicated lists of unwanted
items. From the HISTOGRAM tutorial:

Problem: Remove some elements, listed in random order, from a vector.

IDL> vec=randomu(sd,10)
IDL> remove=[3,7,2,8]
IDL> keep=where(histogram(remove,MIN=0,MAX=n_elements(vec)-1) eq 0,cnt)
IDL> if cnt ne 0 then vec=vec[keep]
IDL> print,keep
0 1 4 5 6 9

We've used HISTOGRAM and WHERE to simply generate a list of kept
indices.

JD
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Where and lists of regions
Next Topic: large array

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

Current Time: Thu Oct 09 21:01:22 PDT 2025

Total time taken to generate the page: 1.99409 seconds