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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: (more) Efficient way to generate an array whose elements are the distance from the center [message #80701] Fri, 06 July 2012 14:05 Go to next message
Mike F. is currently offline  Mike F.
Messages: 2
Registered: July 2012
Junior Member
Amazing! Thanks!
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 next 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
Re: (more) Efficient way to generate an array whose elements are the distance from the center [message #80794 is a reply to message #80702] Sun, 08 July 2012 08:39 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 7/6/12 2:53 PM, fawltylanguage@gmail.com wrote:
> 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
>

Also, DIST is written in dist.pro, so check it out in lib/ to look at
how to do this.

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Oct 08 13:44:03 PDT 2025

Total time taken to generate the page: 0.00701 seconds