next up previous contents
Next: Plotting two lots of Up: Section 2: Introduction to Previous: Using where   Contents

Using where on a 2D array

Suppose we want to change all the 9999999. in our data array to -9999999. Again ``where'' is the quickest way to do this.

w=where(data eq 9999999.)
data(w)=-1.*data(w)

Again, look at ``help,w'' and ``print,w(0:10)'' (the first ten elements of w). ``Where'' has again returned a 1D list of numbers even though data is 2D. Where can be used on arrays of any dimensions, but it always refers to the position of each element with a single number (by just counting through the elements of the array in order).

Also note the useful trick,

w=where(data eq 9999999.,cw)
if cw gt 0 then data(w)=-1.*data(w)
here cw counts how many elements fulfil the conditions.

(Also look at

~lecjm/IDL/Procedures/Logic/Logic/wheretomulti.pro
which is useful for converting 1D lists from where to 2D or 3D subscripts if you ever need to -- although generally you wont have to).



John Marsham 2009-12-07