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

Home » Public Forums » archive » Re: FOR statement
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: FOR statement [message #24752 is a reply to message #24747] Thu, 12 April 2001 09:18 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Eli Beckerman <ebeckerman@cfa.harvard.edu> writes:

> Hey,
>
> I just tried running a FOR loop in the hopes
> of incrementing the variable "i" by steps of 0.25 as follows:
>
> radius=fltarr(1000)
> FOR i=0.0, 100.0, 0.25 DO BEGIN
>
> radius(i)=i
>
> ENDFOR
>
>
> And what I end up with is an array that starts
> with the value 0.75 and is incremented by steps of 1.
>
> I'm following the convention of the FOR statement as
> presented in IDL's online help. What am I doing wrong?!

You appear to be mixing the semantics of indexing with assignment.
What do you think happens when you do radius(0.25) = 0.25, which is
followed by radius(0.5) = 0.5 and radius(0.75) = 0.75? IDL
automatically converts floating point array indices into integers by
rounding down, so all of the statements I just mentioned affect the
same array element, and 0.75 supercedes because it is last.

You probably want:

FOR i=0.0, 100.0, 0.25 DO radius(i*4)=i

Or better yet:

FOR i=0, 999 do radius(i) = i * 0.25
(which avoids the ambiguity of indexing by a floating point number)

Or even better:

radius = findgen(400)*0.25
(avoids FOR loops altogether)

Also, why do you have a 1000 element array when you only fill the
first 400 elements?

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: MAKE_ARRAY question
Next Topic: IDLgrWindow, Map_Patch, and contours

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

Current Time: Sat Oct 11 10:17:28 PDT 2025

Total time taken to generate the page: 1.27921 seconds