matrix.add_row() - Pine Script Function
matrix.add_row()
Section titled “matrix.add_row()”Overview
Section titled “Overview”Inserts a new row at the row index of the id matrix.
Syntax
Section titled “Syntax”matrix.add_row(id, row, array_id) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any matrix type | The matrix object’s ID (reference). |
Remarks
Section titled “Remarks”- Indexing of rows and columns starts at zero. Rather than add rows to an empty matrix, it is far more efficient to declare a matrix with explicit dimensions and fill it with values.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.add_row()` Example 2")if barstate.islastconfirmedhistory // Create an empty matrix object. var m = matrix.new<int>() // Create an array with values `1` and `2`. var a =array.from(1, 2) // Add the `a` array as the first row of the empty matrix. matrix.add_row(m, 0, a) // Display matrix elements. var t =table.new(position.top_right, 2, 2, color.green) table.cell(t, 0, 0, "Matrix elements:") table.cell(t, 0, 1, str.tostring(m))