a1=indgen(5)
HELP,a1
PRINT,a1
You should get the following response:
IDL> @prog3
A1
INT = Array[5]
0
1 2
3 4
You have constructed an array of integers with 1 row and 5 columns.
The entries of the array are set equal to the array index. This counting
scheme is very useful as the foundation for many operations with numbers.
We will explore a few of these as we go.
The response should be like that shown below.
IDL> @prog3
A1
INT = Array[4, 5]
0
1 2
3
4
5 6
7
8
9 10 11
12
13 14 15
16
17 18 19
What information about the function INDGEN can you get from the above display? For example, the first index specifies the number of columns and the second index specifies the number of rows. The total number of elements is ____? The index runs along the ____ from ____ to _____.
a1=indgen(4,5)
HELP,a1
PRINT,a1
b1=5*a1-50
PRINT
PRINT,'The result of 5*a1-50 is:'
PRINT,b1
IDL> @prog3
A1
INT = Array[4, 5]
0
1 2
3
4
5 6
7
8
9 10 11
12
13 14 15
16
17 18 19
The result of 5*a1-50 is:
-50
-45 -40 -35
-30
-25 -20 -15
-10
-5 0
5
10
15 20 25
30
35 40 45
The four lines that have been added do the computation and then print
out the results. We have printed a blank line and a heading so we can keep
track of the results. Take a close look at the results and be sure that
you can explain the entries. Note how simple it was to do a fairly complicated
computation.
a1=indgen(4,5)
HELP,a1
PRINT,a1
b1=5*a1-50
PRINT
PRINT,'The result of 5*a1-50 is:'
PRINT,b1
a2=a1[2:3,0:3]
b2=b1[2:3,0:3]
PRINT
PRINT,'Selection from a1'
PRINT,a2
PRINT
PRINT,'Selection from b1'
PRINT,b2
IDL> @prog3
A1
INT = Array[4, 5]
0
1 2
3
4
5 6
7
8
9 10 11
12
13 14 15
16
17 18 19
The result of 5*a1-50 is:
-50
-45 -40 -35
-30
-25 -20 -15
-10
-5 0
5
10
15 20 25
30
35 40 45
Selection from a1
2
3
6
7
10
11
14
15
Selection from b1
-40
-35
-20
-15
0
5
20
25
Look carefully at the region of a1 and b1 that were selected. Relate these selections to the row and column indexes of the selection statement.
k=[2,3,6,7,10,11,14,15]
PRINT
PRINT,'k selection from b1'
PRINT,b1[k]
IDL> @prog3
A1
INT = Array[4, 5]
0
1 2
3
4
5 6
7
8
9 10 11
12
13 14 15
16
17 18 19
The result of 5*a1-50 is:
-50
-45 -40 -35
-30
-25 -20 -15
-10
-5 0
5
10
15 20 25
30
35 40 45
Selection from a1
2
3
6
7
10
11
14
15
Selection from b1
-40
-35
-20
-15
0
5
20
25
k selection from b1
-40
-35 -20 -15
0 5 20
25
Converting between column,row) indexes and array indexes: Suppose
that the column and row indexes of a particular array location are (C,R)
and that the array has NC columns. Then, as you can verify, the array index
is k=C+R*NC. This gives us a way to calculate the array index if
we are given column and row indexes. Let us test this by constructing the
column and row indexes for the example above and then calculating the values
of k. Since we have selected from columns 2 and 3 and rows 0,1,2,3 we have
the matching coordinate sets
C=[2,3,2,3,2,3,2,3] and R=[0,0,1,1,2,2,3,3]
The number of columns is NC=4. Enter the following statements at the end
of your program and run it. Note that we are using n to represent the computed
value of the index.
NC=4
C=[2,3,2,3,2,3,2,3]
R=[0,0,1,1,2,2,3,3]
n=C+R*NC
PRINT
PRINT,'C=',C
PRINT,'R=',R
PRINT,'k=',k
PRINT,'n=',n
The last four lines of the results show the row and column values as well
as the old and new values for the array index. This is a check on our calculation.
C= 2
3 2
3 2
3 2
3
R= 0
0 1
1 2
2 3
3
k= 2
3 6
7 10 11
14 15
n= 2
3 6
7 10 11
14 15
The last five lines of the output show that the computed value of the
rows and columns agree with the known values.
k= 2
3 6
7 10 11
14 15
R= 0
0 1
1 2
2 3
3
P= 0
0 1
1 2
2 3
3
C= 2
3 2
3 2
3 2
3
Q= 2
3 2
3 2
3 2
3