Creates a matrix with a given number of rows and columns, every cell holding the same starting value.
matrix.new<float>(3, 4, 0.0) is a three-row, four-column grid of zeros. The type goes in angle brackets and can be int, float, bool, string, color or an object type. Without dimensions the matrix starts empty, and rows and columns can then be added.
Cells left without a starting value are na. The total number of elements may not pass 100,000.
Syntax
matrix.new(rows: series int (optional), columns: series int (optional), initial_value: <matrix_type> (optional)) -> matrix<type>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| rows | series int | 0 | Number of rows in the new matrix. 0 gives a matrix with no rows. |
| columns | series int | 0 | Number of columns in the new matrix. 0 gives a matrix with no columns. |
| initial_value | <matrix_type> | na | The value every cell starts with. |
Returns
matrix<type>: A new matrix of the requested type.
Example
//@version=6
indicator("matrix.new: identity", overlay = false)
matrix<float> id = matrix.new<float>(3, 3, 0.0)
for i = 0 to 2
matrix.set(id, i, i, 1.0)
plot(matrix.trace(id), "Trace")See also
Runs on Sidechair