Function range #

Create an array from a range. By default, the range end is excluded. This can be customized by providing an extra parameter includeEnd.

Syntax #

math.range(str [, includeEnd])               // Create a range from a string,
                                             // where the string contains the
                                             // start, optional step, and end,
                                             // separated by a colon.
math.range(start, end [, includeEnd])        // Create a range with start and
                                             // end and a step size of 1.
math.range(start, end, step [, includeEnd])  // Create a range with start, step,
                                             // and end.

Where #

Parameters #

Parameter Type Description
args * Parameters describing the ranges start, end, and optional step.

Returns #

Type Description
Array | Matrix range

Examples #

math.range(2, 6)        // [2, 3, 4, 5]
math.range(2, -3, -1)   // [2, 1, 0, -1, -2]
math.range('2:1:6')     // [2, 3, 4, 5]
math.range(2, 6, true)  // [2, 3, 4, 5, 6]

See also #

ones, zeros, size, subset

Fork me on GitHub