matrix.median() - Pine Script Function
matrix.median()
Section titled “matrix.median()”Overview
Section titled “Overview”The function calculates the median (“the middle” value) of matrix elements.
Syntax
Section titled “Syntax”matrix.median(id) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | matrix<int/float> | A matrix object. |
Remarks
Section titled “Remarks”- Note that na elements of the matrix are not considered when calculating the median.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.median()` Example")// Create a 2x2 matrix.m = matrix.new<int>(2, 2, na)// Fill the matrix with values.matrix.set(m, 0, 0, 1)matrix.set(m, 0, 1, 2)matrix.set(m, 1, 0, 3)matrix.set(m, 1, 1, 4)// Get the median of the matrix.x = matrix.median(m)plot(x, 'Median of the matrix')