next up previous contents
Next: Default array operations Up: Section 3: Some ``nuts Previous: Other flow control statements   Contents

Array operations

IDL allows you to do many operations on whole arrays. E.g. instead of:

 
IDL> n=5
IDL> x=indgen(n)
IDL> xsquared = fltarr(n)                        ;LINE A
IDL> for j=0,n-1 do xsquared(j) = x(j) * x(j)      ;LINE B
IDL> print,xsquared
       0       1       4       9      16

Instead of LINES A and B use:

 
IDL> xsquared = x*x
Shorter, clearer and make it much faster. IDL is not a true compiled language - it does NOT compile the program into machine code like the C compiler does.



Subsections

John Marsham 2009-12-07