matrix.transpose() - Pine Script Function
matrix.transpose()
Section titled “matrix.transpose()”Overview
Section titled “Overview”The function creates a new, transposed version of the id. This interchanges the row and column index of each element.
Syntax
Section titled “Syntax”matrix.transpose(id) → matrix<type>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any matrix type | A matrix object. |
Returns
Section titled “Returns”A new matrix containing the transposed version of the id matrix.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.transpose()` Example")// For efficiency, execute this code only once.if barstate.islastconfirmedhistory // Create a 2x2 matrix.var m1 = matrix.new<float>(2, 2, na) // Fill the matrix with values. matrix.set(m1, 0, 0, 1)matrix.set(m1, 0, 1, 2)matrix.set(m1, 1, 0, 3)matrix.set(m1, 1, 1, 4) // Create a transpose of the matrix.var m2 = matrix.transpose(m1) // Display using a table.var t = table.new(position.top_right, 2, 2, color.green)table.cell(t, 0, 0, "Original matrix:")table.cell(t, 0, 1, str.tostring(m1))table.cell(t, 1, 0, "Transposed matrix:")table.cell(t, 1, 1, str.tostring(m2))