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

Home » Public Forums » archive » (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 
Switch to threaded view of this topic Create a new topic Submit Reply
(more) Efficient way to generate an array whose elements are the distance from the center [message #80703] Fri, 06 July 2012 13:37
Mike F. is currently offline  Mike F.
Messages: 2
Registered: July 2012
Junior Member
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!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Function graphics /OVERPLOT redefines axis limits after plot with /NODATA
Next Topic: Passing variables between procedures

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

Current Time: Wed Oct 08 11:45:10 PDT 2025

Total time taken to generate the page: 0.00517 seconds