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

Home » Public Forums » archive » Re: (more) Efficient way to generate an array whose elements are the distance from the center
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: (more) Efficient way to generate an array whose elements are the distance from the center [message #80702 is a reply to message #80701] Fri, 06 July 2012 13:53 Go to previous messageGo to previous message
Lajos Foldy is currently offline  Lajos Foldy
Messages: 176
Registered: December 2011
Senior Member
On Friday, July 6, 2012 10:37:35 PM UTC+2, Mike F. wrote:
> Hello all.
>
> I'm new to IDL (and coding in general), and I'm looking to find a more efficient way to generate an nxn array where each element is the distance from the center of the array.
>
> 3 x 3 Ex: 1.4 1 1.4
> 1 0 1
> 1.4 1 1.4
>
> All I can think of on my own is a nested FOR loop as such:
>
> FOR i = 0l, (n - 1) DO BEGIN
> FOR j = 0l, (n - 1) DO BEGIN
>
> plane[i,j] = SQRT( (i-n/2.)^2 + (j - n/2.)^2 )
>
> ENDFOR
> ENDFOR
>
> From what I've read on IDL forums, nested FOR loops are the pinnacle of sin, and I'd like to be a bit more pious if possible.
>
> Any tips would be appreciated!

Look up DIST and SHIFT in the docs:

IDL> print, shift(dist(3),1,1)
1.41421 1.00000 1.41421
1.00000 0.00000 1.00000
1.41421 1.00000 1.41421

regards,
Lajos
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: monthly mean of data
Next Topic: Re: convert from Julian date to calendar date and vice verse

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

Current Time: Sun Oct 12 00:27:13 PDT 2025

Total time taken to generate the page: 0.80247 seconds