Sidechair

matrix.add_col()

Browse the reference

Inserts an array as a new column of a matrix, at the end unless you give a position.

Try it in the editor

The array supplies the new column's items and needs as many items as the matrix has rows. Columns from the chosen position rightward move one place. Leave out column to append.

On an empty matrix the array's length decides the row count, so a matrix can be built from series one column at a time.

Syntax

Pine Script
matrix.add_col(id: any matrix type, column: series int (optional), array_id: any array type) -> void
matrix.add_col(column: series int (optional), array_id: any array type) -> void

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix that receives the new column. Its column count grows by one.
columnseries intthe end of the matrixIndex of the column. Counts from 0.
array_idany array typerequiredThe array whose items become the new row or column.

Returns

Nothing.

Example

Pine ScriptAdd a column of onesOpen in editor
//@version=6
indicator("matrix.add_col: bias column", overlay = false)
matrix<float> m = matrix.new<float>(3, 2, 0.0)
matrix.add_col(m, matrix.columns(m), array.from(1.0, 1.0, 1.0))
plot(matrix.columns(m), "Columns")

See also

Runs on Sidechair