Programmer Guide > Using Subscripts with Arrays > Subscript Ranges
  

Subscript Ranges
Subscript ranges are used to select a subarray from an array by giving the starting and ending subscripts of the subarray in each dimension.
Subscript ranges may be combined with scalar and array subscripts and with other subscript ranges. Any rectangular portion of an array may be selected with subscript ranges. Subscript Ranges lists the available subscript ranges.
There are four types of subscript ranges:
*A range of subscripts, written (e0 : e1), denoting all elements whose subscripts range from the expression e0 to e1. e0 must not be greater than e1 (but it may equal e1).
*For example, if the variable VEC is a 50-element vector,
VEC(5 : 9)
*is a 5-element vector composed of
[VEC(5), ..., VEC(9)]
*All elements from a given element to the last element of the dimension, written as (E : *).
*Using the above example,
VEC(10 : *)
*is a 40-element vector made of
[VEC(10), ..., VEC(49)]
*A simple subscript, (n). When used with multidimensional arrays, simple subscripts specify only elements with subscripts equal to the given subscript in that dimension.
*All elements of a dimension, written (*). This form is used with multidimensional arrays to select all elements along the dimension.
*For example, if ARR is a 10-by-12 array,
ARR(*, 11) 
*is a 10-element vector composed of elements
[ARR(0, 11), ARR(1, 11), ..., ARR(9, 11)] 
*Similarly,
ARR(0, *)
*is the 1-by-12 array,
[ARR(0, 0), ARR(0, 1), ..., ARR(0, 11)] 
Multidimensional subarrays may be specified using any combination of the above forms. For example,
ARR(*, 0 : 4)
is a 10-by-5 array. Or, if ARR is a 5 by 10 by 15 by 20 array, then ARR(0, 1:2, 3:*, *) is a 1 by 2 by 12 by 20 array.
 
Table 5-1: Subscript Ranges  
Form
Meaning
E
A simple subscript expression
e0 : e1
Subscript range from e0 to e1
E : *
All points from element E to end
*
All points in the dimension

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.