The following examples illustrate aspects of IDL's array syntax with one-dimensional arrays. Note that the functions 'indgen' and 'findgen' are handy ways of generating arrays of integers and reals respectively. The array indexing runs from 0 to N-1 where N is the number of elements. Multiple commands on one line are separated by &. The array 'c' is set equal to 'a' as a way of declaring it. More array syntax is mentioned in the description of plotting graphs on the main lab page.
IDL> a=findgen(10)+1. & print,a
1.00000 2.00000 3.00000 4.00000 5.00000 6.00000
7.00000 8.00000 9.00000 10.0000
IDL> b=2*a & print,b
2.00000 4.00000 6.00000 8.00000 10.0000 12.0000
14.0000 16.0000 18.0000 20.0000
IDL> c=a & for i=0,9 do c[i]=b[i]/a[i]
IDL> print,c
2.00000 2.00000 2.00000 2.00000 2.00000 2.00000
2.00000 2.00000 2.00000 2.00000
Back to lab1 home page