Sidechair

matrix.set()

Browse the reference

Stores a value in a given row and column of a matrix.

Try it in the editor

matrix.set(m, 1, 0, 5.0) overwrites the second row's first item. The cell has to exist already; grow the matrix with matrix.add_row() or matrix.add_col() first.

The value must match the matrix's element type.

Syntax

Pine Script
matrix.set(id: any matrix type, row: series int, column: series int, value: series <type of the matrix's elements>) -> void
matrix.set(row: series int, column: series int, value: series <type of the matrix's elements>) -> void

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to write into. Only the item at the chosen row and column is replaced.
rowseries intrequiredIndex of the row. Counts from 0.
columnseries intrequiredIndex of the column. Counts from 0.
valueseries <type of the matrix's elements>requiredThe value to store. It has to match the type of the matrix's elements.

Returns

Nothing.

Example

Pine ScriptFill a diagonal from closesOpen in editor
//@version=6
indicator("matrix.set: diagonal", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 0.0)
matrix.set(m, 0, 0, close)
matrix.set(m, 1, 1, open)
plot(matrix.trace(m), "Open plus close")

See also

Runs on Sidechair