next up previous contents
Next: A word of warning Up: Arrays Previous: Creating arrays   Contents

Subsets of arrays

You can refer to elements of the array using [] or ():
IDL> an_array=[3, 5, 6, 2.5, 100, 27.7]
IDL> print,an_array[0],an_array[2],an_array(0)
      3.00000      6.00000       3.00000
You can refer to a subset of the array like this:
IDL> an_array=[3, 5, 6, 2.5, 100, 27.7]
print,an_array[3:5]
      2.50000      100.000      27.7000

IDL> array_2d= [[ 2,3,4],[10,20,30]]; 3 columns , 2 rows 
i.e. 10 , 20 , 30
     2  , 3  , 4

IDL> print,array_2d[0,1]
      10
IDL> print,array_2d[1:2,1]
      20      30
IDL> print,array_2d[2,*]
       4
      30
An asterisk, *, is used to represent an entire column or row of the array.

Use can also refer to elements by their one-dimensional subscripts E. g.

print,array_2d([1,2,3])
      3       4      10



John Marsham 2009-12-07