Sidechair

matrix.submatrix()

Browse the reference

Returns a new matrix holding a block of an existing one.

Try it in the editor

The block runs from from_row up to, but not including, to_row, and the same for columns. Left out, the range covers the whole matrix, so the call is a full copy.

The result is a separate matrix; changing it does not change the source.

Syntax

Pine Script
matrix.submatrix(id: any matrix type, from_row: series int (optional), to_row: series int (optional), from_column: series int (optional), to_column: series int (optional)) -> matrix<>
matrix.submatrix(from_row: series int (optional), to_row: series int (optional), from_column: series int (optional), to_column: series int (optional)) -> matrix<>

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to cut a block from. The block is returned as a new matrix.
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

matrix<>: A new matrix with the selected rows and columns.

Example

Pine ScriptTop-left 2 by 2Open in editor
//@version=6
indicator("matrix.submatrix: corner", overlay = false)
matrix<float> m = matrix.new<float>(3, 3, 5.0)
corner = matrix.submatrix(m, 0, 2, 0, 2)
plot(matrix.rows(corner), "Rows in block")

See also

Runs on Sidechair