matrix.add_col() - Pine Script Function
matrix.add_col()
Section titled “matrix.add_col()”Overview
Section titled “Overview”Inserts a new column at the column index of the id matrix.
Syntax
Section titled “Syntax”matrix.add_col(id, column, array_id) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any matrix type | The matrix object’s ID (reference). |
Remarks
Section titled “Remarks”- Rather than add columns to an empty matrix, it is far more efficient to declare a matrix with explicit dimensions and fill it with values. Adding a column is also much slower than adding a row with the matrix.add_row function.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.add_col()` Example 2")if barstate.islastconfirmedhistory // Create an empty matrix object. var m = matrix.new<int>() // Create an array with values `1` and `3`. var a =array.from(1, 3) // Add the `a` array as the first column of the empty matrix. matrix.add_col(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))