Back Home Up Next

Subchapters:

Working with arrays

The < and > symbols will perform a min and max on a table, useful if you have to take the log of a table where negative values could be:

        IDL> print,sin(tab1)
                 0.997495     0.909297     0.141120
                 0.909297     0.141120    -0.756802
                 0.656987     0.412118      0.00000
        IDL> print,alog(sin(tab1))
              -0.00250815   -0.0950831     -1.95814
               -0.0950831     -1.95814         -Inf
                -0.420092    -0.886444         -Inf
            % Program caused arithmetic error: Floating divide by 0
            % Program caused arithmetic error: Floating illegal operand

Here we will substitute all the value lower than 0.0001 by 0.0001:

        IDL> print,sin(tab1) > 0.0001
                 0.997495     0.909297     0.141120
                 0.909297     0.141120  0.000100000
                 0.656987     0.412118  0.000100000

Now we can take the log of the table, without errors (but you have to deal with the -9.12... value.):

        IDL> print,alog(sin(tab1) > 0.0001)
              -0.00250815   -0.0950831     -1.95814
               -0.0950831     -1.95814     -9.21034
                -0.420092    -0.886444     -9.21034

We can choose to work on a subset of tab1, where the values are > 0., see next Chapter about the "where" function.

If you want to compare 2 arrays, you can always overplot them on the same plot, but you cannot, for ex., subtract one to the other unless you rebin them:

IDL> x1 = findgen(200)/199.
IDL> y1 = x1^2
IDL> x2 = findgen(3000)/2999.
IDL> y2 = x2^(2.1)
IDL> plot,x1,y1
IDL> oplot,x2,y2
IDL> y2_bis = interpol(y2,x2,x1)
IDL> help,x1,y1,y2,y2_bis
IDL> plot,x1,y1-y2_bis

see also interpolate.

 

IDL courses C. Morisset © 2004 IA/UNAM V 2.2

Back Home Up Next