matrix.diff() - Pine Script Function
matrix.diff()
Section titled “matrix.diff()”Overview
Section titled “Overview”The function returns a new matrix resulting from the subtraction between matrices id1 and id2, or of matrix id1 and an id2 scalar (a numerical value).
Syntax
Section titled “Syntax”matrix.diff(id1, id2) → matrix<int>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id1 | matrix | Matrix to subtract from. |
Returns
Section titled “Returns”A new matrix object containing the difference between id2 and id1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.diff()` Example 2")// For efficiency, execute this code only once.if barstate.islastconfirmedhistory // Create a 2x3 matrix with values `4`.var m1 = matrix.new<float>(2, 3, 4) // Create a new matrix containing the difference between the `m1` matrix and the "int" value `1`.var m2 = matrix.diff(m1, 1) // Display using a table.var t = table.new(position.top_right, 1, 2, color.green)table.cell(t, 0, 0, "Difference between a matrix and a scalar:")table.cell(t, 0, 1, str.tostring(m2))