Programmer Guide > Using Subscripts with Arrays > Structure of Subarrays
  

Structure of Subarrays
The dimensions of an extracted subarray are determined by the size in each dimension of the subscript range. In general, the number of dimensions is equal to the number of subscripts. The size of a dimension is equal to 1 if a simple subscript was used for that dimension; otherwise it is equal to the number of elements selected by the range.
Degenerate dimensions (trailing dimensions whose size is equal to 1) are removed. This was illustrated in the above example by the expression ARR(*, 11) which resulted in a vector with a single dimension because the last dimension of the result was 1 and was removed. On the other hand, the expression ARR(0, *) became an array with dimensions of (1, 12) because the dimension with a size of 1 does not appear at the end.
Using the examples of VEC, a 50-element vector, and A, a 10-by-12 array, some typical subscript range expressions are:
; Points 5 to 10 of VEC, a 6-element vector.
VEC(5 : 10)
; 3-point neighborhood around I: [VEC(I – 1), VEC(I), VEC(I + 1)].
VEC(I - 1 : I + 1)
; Points in VEC from VEC(4) to the end, a 50 – 4 = 46-element 
; vector.
VEC(4 : *)
; A 1-by-12 array: [A(3, 0), A(3, 1), ..., A(3, 11)]. 
A(3, *)
; A 10-element vector. 
A(*, 0)
; The 9-point neighborhood surrounding A(X,Y), a 3-by-3 array. 
A(X - 1 : X + 1, Y - 1 : Y + 1)
; A 3-by-12 subarray. 
A(3 : 5, *)
One-dimensional range subscripts can be used with multidimensional arrays. For example, if A is a 2 by 2 by 2 by 2 by 2 array, then A(*) is a 32-element vector containing all the elements of A, and A(5:*) is a vector containing the last 27 elements of A.
Arrays as well as scalars can be assigned to array elements referenced by range subscripts.
Examples
a = FLTARR( 5, 5 )    &    a(*) = 1    &    a(0:3,1:*) = 2    &    PM, a
 
1.00000
2.00000
2.00000
2.00000
2.00000
1.00000
2.00000
2.00000
2.00000
2.00000
1.00000
2.00000
2.00000
2.00000
2.00000
1.00000
2.00000
2.00000
2.00000
2.00000
1.00000
1.00000
1.00000
1.00000
1.00000
a = FLTARR( 2, 4 )    &    a(*) = INDGEN( 8 )    &    PM, a
 
0.00000
2.00000
4.00000
6.00000
1.00000
3.00000
5.00000
7.00000
a = DBLARR( 3, 3, 3 )    &    a(*,1:*,0) = INDGEN( 6 )    &    PM, a
 
0.0000000
0.0000000
0.0000000
0.0000000
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
a(*,*,2) = REPLICATE( 1, 3, 3 )    &    PM, a
 
0.0000000
0.0000000
0.0000000
0.0000000
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
a(0:0,2:2,2:*) = 2    &    PM, a
 
 
 
0.0000000
0.0000000
0.0000000
0.0000000
1.0000000
2.0000000
3.0000000
4.0000000
5.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
0.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
1.0000000
2.0000000
1.0000000
1.0000000
See the section "Assignment Statement" for more information describing the assigning of values to subarrays.

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.