IDL array subscript

来源:互联网 发布:短信验证码数据库设计 编辑:程序博客网 时间:2024/05/11 04:57

There are six types of subscript ranges:

Subscript Format

Description

[*]

All elements of a dimension.

This form is used with multidimensional arrays to select all elements along the dimension. For example, if arr is a 10-column by 12-row array, arr[*, 11] is the last row of arr, composed of elements [arr[0,11], arr[1,11], ..., arr[9,11]], and is a 10-element row vector. Similarly,arr[0, *] is the first column of arr[arr[0,0], arr[0,1],..., arr[0,11]], and its dimensions are 1 column by 12 rows.

[s0:s1]

Subscript range from s0 to s1.

This denotes all elements whose subscripts range from the expression s0 through s1(s0 must not be greater than s1). For example, if the variable vec is a 10-element vector, vec[4:8] is a five-element vector composed of vec[4] through vec[8]. Negative indices may be used, where -1 indicates the last element. For example, vec[-6:-2] returns the same five elements as vec[4:8].

[s0:*]

or

[s0:-1]

A range from the given element to the last element of dimension.

This denotes all elements from a given element to the last element of the dimension. If the variablevec is a 50-element vector, vec[10:*] is a 40-element vector made from vec[10] through vec[49].

[s0:s1:n]

Every n-th element in a range of subscripts from s0 to s1.

The expression n is referred to as the subscript stride. The stride value may be positive or negative (but must not be zero). If the stride is positive then s0 must be less than or equal to s1. If the stride is negative then s0 must be greater than or equal to s1. If the stride is 1, then the result is identical in meaning to [s0:s1], as described above. For example, if the variable vec is a 50-element vector,vec[5:13:2] is a five-element vector composed of vec[5]vec[7]vec[9]vec[11], and vec[13]. In another example, vec[-1:0:-3] would return every third element of vec, in reverse order.

[s0:*:n]

or

[s0:-1:n]

Every n-th element from element s0 to the end of the dimension.

The expression n is referred to as the subscript stride. If the variable vec is a 50-element vector,vec[10:*:4] is a 10-element vector made from every fourth element between vec[10] throughvec[46].

[n]

A simple subscript, either positive or negative.

Positive subscripts are indexed from the beginning of the array, while negative subscripts are indexed from the end (where -1 is the last element). When used with multidimensional arrays, simple subscripts specify only elements with subscripts equal to the given subscript in that dimension.

Multidimensional subarrays can be specified using any combination of the above forms. For example, if arr is a 10x10 array, arr[*,0:4] returns a 10 x 5 array that is made from all columns of rows 0 to 4 of arr.

0 0