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

Home » Public Forums » archive » Re: Help with getting rid of a FOR loop
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: Help with getting rid of a FOR loop [message #60485 is a reply to message #60484] Tue, 20 May 2008 15:55 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> dist=sqrt((xx-xcenter)^2+(yy-ycenter)^2) ;array of radii
>
> mask=fltarr(imsize,imsize)-1
>
> FOR i=0,num-1 DO BEGIN
> wh=where(dist GE r[i] and dist LE r[i+1])
> mask[wh]=i
> ENDFOR
>
> END
>
> I would like to find some way to get rid of the FOR loop at the end.
> All I'm doing in that loop is going through the annuli one by one,
> finding the pixels in that annuli, and setting the corresponding
> pixels in mask to the correct mask value.
>
> Thanks for any help anyone can provide!
>
> Nathan Goldbaum

Hi Nathan,

if your computer memory permits it, you can
1) reform your dist array so it is now a n_elements(dist) *
n_elements(r) array. basically, you will copy the distances
n_elements(r) times.
2) reform your r array so it is now a n_elements(dist) * n_elements(r)
array.
3) shift the array from (2) by 1
4) do where(new_dist GT new_r and new_dist LT new_r_plus_1)
5) divide the returned index by n_elements(r). You will know, for each
r, which elements satisfies your condition!

Sorry if it is not too clear... that's a "quick answer before to leave"...
Jean
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: iTools export to variable woes
Next Topic: interact with iimage from the command line?

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

Current Time: Sat Oct 11 06:45:12 PDT 2025

Total time taken to generate the page: 0.72085 seconds