1 |
|
2 |
|
3 | # Function range
|
4 |
|
5 | Create an array from a range.
|
6 | By default, the range end is excluded. This can be customized by providing
|
7 | an extra parameter `includeEnd`.
|
8 |
|
9 |
|
10 | ## Syntax
|
11 |
|
12 | ```js
|
13 | math.range(str [, includeEnd]) // Create a range from a string,
|
14 | // where the string contains the
|
15 | // start, optional step, and end,
|
16 | // separated by a colon.
|
17 | math.range(start, end [, includeEnd]) // Create a range with start and
|
18 | // end and a step size of 1.
|
19 | math.range(start, end, step [, includeEnd]) // Create a range with start, step,
|
20 | // and end.
|
21 | ```
|
22 |
|
23 | ### Where
|
24 |
|
25 | - `str: string`
|
26 | A string 'start:end' or 'start:step:end'
|
27 | - `start: {number | BigNumber}`
|
28 | Start of the range
|
29 | - `end: number | BigNumber`
|
30 | End of the range, excluded by default, included when parameter includeEnd=true
|
31 | - `step: number | BigNumber`
|
32 | Step size. Default value is 1.
|
33 | - `includeEnd: boolean`
|
34 | Option to specify whether to include the end or not. False by default.
|
35 |
|
36 | ### Parameters
|
37 |
|
38 | Parameter | Type | Description
|
39 | --------- | ---- | -----------
|
40 | `args` | * | Parameters describing the ranges `start`, `end`, and optional `step`.
|
41 |
|
42 | ### Returns
|
43 |
|
44 | Type | Description
|
45 | ---- | -----------
|
46 | Array | Matrix | range
|
47 |
|
48 |
|
49 | ## Examples
|
50 |
|
51 | ```js
|
52 | math.range(2, 6) // [2, 3, 4, 5]
|
53 | math.range(2, -3, -1) // [2, 1, 0, -1, -2]
|
54 | math.range('2:1:6') // [2, 3, 4, 5]
|
55 | math.range(2, 6, true) // [2, 3, 4, 5, 6]
|
56 | ```
|
57 |
|
58 |
|
59 | ## See also
|
60 |
|
61 | [ones](ones.md),
|
62 | [zeros](zeros.md),
|
63 | [size](size.md),
|
64 | [subset](subset.md)
|