[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FOR statement



Eli Beckerman wrote:
> In defense of myself, I wasn't using the FOR loop to make an array
> (I just excluded all the unnecessary stuff from my posting, and
> seemingly confused everyone even further!)
> 
> But clearly, I was mixing the semantics of indexing with assignment
> as Craig pointed out!
> 
> FOR i=0, 999 do radius(i) = i * 0.25 is the way to go for what I
> wanted. Thanks for seeing through my morning foggyness.

Eli,

No matter how look at it, your example shows you *are* using a loop to
create an evenly spaced mesh vector. I guess I was trying to say that
using a loop is not the best way to do this in IDL. One of the wisest
pieces of advice I ever received about IDL programming was

"Try to think like an IDL programmer, not a Fortran or C programmer".

In this spirit, I submit that the following method is preferable:

nx = 1000    ; number of values required
dx = 0.25    ; step size
x1 = 0.0     ; start value
radius = lindgen(nx) * dx + x1

You might try changing the number of values to 10,000,000 and seeing
which method is faster.

Cheers,
Liam.