Sidechair

matrix.fill()

Browse the reference

Sets every item of a matrix, or of a block inside it, to one value.

Try it in the editor

matrix.fill(m, 0.0) zeroes the whole grid. Pass from_row, to_row, from_column and to_column to fill a block; each end is exclusive, so to_row = 2 fills rows 0 and 1.

A block that falls outside the matrix stops the script with an error naming the offending index.

Syntax

Pine Script
matrix.fill(id: any matrix type, value: series <type of the matrix's elements>, from_row: series int (optional), to_row: series int (optional), from_column: series int (optional), to_column: series int (optional)) -> void
matrix.fill(value: series <type of the matrix's elements>, from_row: series int (optional), to_row: series int (optional), from_column: series int (optional), to_column: series int (optional)) -> void

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to overwrite, all of it or the block chosen by the row and column ranges.
valueseries <type of the matrix's elements>requiredThe value to store. It has to match the type of the matrix's elements.
from_rowseries int0First row of the range. Counts from 0.
to_rowseries intthe number of rowsRow just after the last row of the range.
from_columnseries int0First column of the range. Counts from 0.
to_columnseries intthe number of columnsColumn just after the last column of the range.

Returns

Nothing.

Example

Pine ScriptZero the top-left blockOpen in editor
//@version=6
indicator("matrix.fill: block", overlay = false)
matrix<float> m = matrix.new<float>(3, 3, 1.0)
matrix.fill(m, 0.0, 0, 2, 0, 2)
plot(matrix.get(m, 0, 0) + matrix.get(m, 2, 2), "Zeroed cell plus untouched cell")

See also

Runs on Sidechair