## 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 can be combined with scalar and array subscripts and with other subscript ranges. Any rectangular portion of an array can be selected with subscript ranges. There are six types of subscript ranges:

• A range of subscripts, written [e0:e1], denoting all elements whose subscripts range from the expression e0 through e1 (e0 must not be greater than e1). For example, if the variable `vec` is a 50-element vector, `vec[5:9]` is a five-element vector composed of `vec[5]` through `vec[9]`.
• A range of subscripts, written [ e0:e1:e2 ], denoting every e2th element within the range of subscripts e0 through e1 ( e0 must not be greater than e1). e2 is referred to as the subscript stride. The stride value must be greater than or equal to 1. If it is set to the value 1, the resulting subscript expression is identical in meaning to [e0:e1], 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]`.
• All elements from a given element to the last element of the dimension, written as [e0:*]. Using the above example, `vec[10:*]` is a 40-element vector made from `vec[10]` through `vec[49]`.
• Every e2th element from a given element to the last element of the dimension, written as [e0:*:e2]. e2 is referred to as the subscript stride. The stride value must be greater than or equal to 1. If it is set to the value 1, the resulting subscript expression is identical in meaning to [e0:*], as described above. Using the above example, `vec[10:*:4]` is a 10-element vector made from every fourth element between `vec[10]` through `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-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.

Multidimensional subarrays can be specified using any combination of the above forms. For example, `arr[*, 0:4]` is made from all columns of rows 0 to 4 of `arr` or a 10-column, 5-row array. The table below summarizes the possible forms of subscript ranges:

Form
Description
e
A simple subscript expression
e 0:e 1
Subscript range from e 0 to e 1
e 0:e 1:e 2
Subscript range from e 0 to e 1 with a stride of e 2
e 0:*
All points from element e 0 to end
e 0:*:e 2
All points from element e 0 to end with a stride of e 2
*
All points in the dimension