Function range #

创建一个包含一系列值的矩阵或数组。默认情况下,范围的结束值不包含在内。可以通过提供一个额外的参数 `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 * 描述范围的 `start`、`end` 和可选的 `step` 的参数。

Returns #

Type Description
Array | Matrix range

Throws #

Type | Description —- | ———–

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]
math.range(2, math.fraction(8,3), math.fraction(1,3)) // [fraction(2), fraction(7,3)]
math.range(math.unit(2, 'm'), math.unit(-3, 'm'), math.unit(-1, 'm')) // [2 m, 1 m, 0 m , -1 m, -2 m]

另请参阅 #

ones, zeros, size, subset

Fork me on GitHub