Home > @josh-brown/vector > MatrixBuilder > slice
Constructs a new matrix based on a rectangular slice of a larger matrix
Signature:
slice(matrix: Matrix<S>, rowStartIndex?: number, columnStartIndex?: number, rowEndIndex?: number, columnEndIndex?: number): M;|
Parameter |
Type |
Description |
|---|---|---|
|
matrix |
Matrix<S> |
The original matrix |
|
rowStartIndex |
number |
(Optional) The (inclusive) first row of the slice |
|
columnStartIndex |
number |
(Optional) The (inclusive) first column of the slice |
|
rowEndIndex |
number |
(Optional) The (exclusive) last row of the slice |
|
columnEndIndex |
number |
(Optional) The (exclusive) last column of the slice |
Returns:
M
The new matrix
const matrix = matrixBuilder.identity(4);
const slice = matrixBuilder.slice(matrix, 2, 2, 3, 4);
// [ 1 0 0 0 ]
// [ 0 1* 0* 0* ] => [ 1 0 0 ]
// [ 0 0* 1* 0* ] [ 0 1 0 ]
// [ 0 0 0 1 ]