| Re: how to do a loop in idl using multi-commmand? [message #43516] |
Sun, 17 April 2005 22:37  |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Hi,
"lixiaoyao" <lixiaoyao5880@yahoo.com> wrote in message
news:1113584939.738412.136930@o13g2000cwo.googlegroups.com.. .
> I can run this in my idl,who know how to solve it?
> nH2=findgen(10001)*10.0+0.1
> ratio=make_array(10001)
> for i=0,10000 do
> x=2*nH2[i]
> y=x*nH2[i]
> ratio[i]=x/y
> openw,1,'file'
> printf,1,ratio
> close,1
> it seems to show you can not do multicommand in do loop.
> thanks
The suggestions that others have given are all great, but you may want to
know that you can do the work of this loop using IDL's powerful (and much
faster) array operations as follows:
nH2=findgen(10001)*10.0+0.1
x=2*nH2
y=x*nH2
ratio=x/y
or, if you don't need to make x and y for any other reason:
ratio = (2*nH2) / (2*nH2*nH2)
or then, by factoring:
ratio = 1 / nH2
A useful section in IDL Online Help that covers some features that are
different from many other languages is "Writing Efficient IDL Programs" (in
Programming in IDL:Basics of IDL Programming).
Cheers,
--
-Dick
Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
|
|
|
|