Re: Where and lists of regions [message #41317 is a reply to message #41316] |
Mon, 11 October 2004 21:39   |
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
|
|
|