IDL作为一种完全面向矩阵的动态语言,数组是其最基本的结构,在IDL中可直接对数组进行扩展,这在C#和Java这类编译型语言中,是无法做到的。在C#和Java中实现动态数据结构,往往需要用到List,Array,Vector等动态数组封装类,通过这些类中的Add和Delete等方法来对元素进行操作。在IDL中,对数据的动态操作非常方便,数组大小和结构可根据运行候程序的需要自动变化。在数组元素无法确定时,常采用数组合并的方式来动态的扩充数组,同时保持数组原有元素的不变性。数组合并的运算符为“[ ]”,关于“[ ]”操作符,IDL帮助中描述如下:
[ ]:Array concatenation
The expression [A,B] is an array formed by concatenating A and B, which can be scalars or arrays, along the first dimension.
To concatenate second and third levels, nest the brackets; [[1,2],[3,4]] is a 2-element by 2-element array with the first row containing 1 and 2 and the second row containing 3 and 4. Operands must have compatible dimensions; all dimensions must be equal except the dimension that is to be concatenated, e.g., [2,INTARR(2,2)] are incompatible.
Eg:
Define C as three-point vector:
C = [0, 1, 3]
Add 5 to the end of C:
PRINT, [C, 5]
IDL Prints: 0 1 3 5
Insert -1 at the beginning of C:
PRINT, [-1, C]
IDL Prints: -1 0 1 3
Plot ARR2 appended to ARR1.
PLOT, [ARR1, ARR2]
Define a 3x3 matrix.
KER = [[1,2,1], [2,4,2], $ [1,2,1]]
Note - Array concatenation is a relatively inefficient operation, and should only be performed once for a given set of data if possible.
一维数组合并
a = [1,2,3]
b = [4,5,6]
c=[a,b]
print,c
1 2 3 4 5 6
行数相同的二维数组合并
行数相同,直接用[]。相当于matlab中的[a,b]
IDL> a=indgen(2,5)
IDL> print,a
0 1
2 3
4 5
6 7
8 9
IDL> b=indgen(4,5)
IDL> print,b
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19
IDL> ;行数相同,直接用[].相当于matlab中的[a,b]
IDL> c=[a,b]
IDL> help,c
C INT = Array[6, 5]
IDL> print,c
0 1 0 1 2 3
2 3 4 5 6 7
4 5 8 9 10 11
6 7 12 13 14 15
8 9 16 17 18 19
列数相同的二维数组合并
用[[],[]]。相当于matlab中的[a;b]
IDL> d=indgen(2,3)
IDL> print,d
0 1
2 3
4 5
IDL> ;列数相同,需用[[],[]]
IDL> e=[[a],[d]]
IDL> help,e
E INT = Array[2, 8]
IDL> print,e
0 1
2 3
4 5
6 7
8 9
0 1
2 3
4 5
5845



被折叠的 条评论
为什么被折叠?



