matrix.submatrix() - Pine Script Function
matrix.submatrix()
Section titled “matrix.submatrix()”Overview
Section titled “Overview”The function extracts a submatrix of the id matrix within the specified indices.
Syntax
Section titled “Syntax”matrix.submatrix(id, from_row, to_row, from_column, to_column) → matrix<type>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any matrix type | A matrix object. |
Returns
Section titled “Returns”A new matrix object containing the submatrix of the id matrix defined by the from_row, to_row, from_column and to_column indices.
Remarks
Section titled “Remarks”- Indexing of the rows and columns starts at zero.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.submatrix()` Example")// For efficiency, execute this code only once.if barstate.islastconfirmedhistory // Create a 2x3 matrix matrix with values `0`.var m1 = matrix.new<int>(2, 3, 0) // Fill the matrix with values. matrix.set(m1, 0, 0, 1)matrix.set(m1, 0, 1, 2)matrix.set(m1, 0, 2, 3)matrix.set(m1, 1, 0, 4)matrix.set(m1, 1, 1, 5)matrix.set(m1, 1, 2, 6) // Create a 2x2 submatrix of the `m1` matrix.var m2 = matrix.submatrix(m1, 0, 2, 1, 3) // Display using a table.var t = table.new(position.top_right, 2, 2, color.green)table.cell(t, 0, 0, "Original Matrix:")table.cell(t, 0, 1, str.tostring(m1))table.cell(t, 1, 0, "Submatrix:")table.cell(t, 1, 1, str.tostring(m2))