UNPKG

1.51 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function subset
4
5Get or set a subset of a matrix or string.
6
7
8## Syntax
9
10```js
11math.subset(value, index) // retrieve a subset
12math.subset(value, index, replacement [, defaultValue]) // replace a subset
13```
14
15### Parameters
16
17Parameter | Type | Description
18--------- | ---- | -----------
19`matrix` | Array &#124; Matrix &#124; string | An array, matrix, or string
20`index` | Index | An index containing ranges for each dimension
21`replacement` | * | An array, matrix, or scalar. If provided, the subset is replaced with replacement. If not provided, the subset is returned
22`defaultValue` | * | Default value, filled in on new entries when the matrix is resized. If not provided, math.matrix elements will be left undefined. Default value: undefined.
23
24### Returns
25
26Type | Description
27---- | -----------
28Array &#124; Matrix &#124; string | Either the retrieved subset or the updated matrix.
29
30
31## Examples
32
33```js
34// get a subset
35const d = [[1, 2], [3, 4]]
36math.subset(d, math.index(1, 0)) // returns 3
37math.subset(d, math.index([0, 1], 1)) // returns [[2], [4]]
38
39// replace a subset
40const e = []
41const f = math.subset(e, math.index(0, [0, 2]), [5, 6]) // f = [[5, 6]]
42const g = math.subset(f, math.index(1, 1), 7, 0) // g = [[5, 6], [0, 7]]
43```
44
45
46## See also
47
48[size](size.md),
49[resize](resize.md),
50[squeeze](squeeze.md),
51[index](index.md)