median
Statistical median of a data set.
Syntax
median(expr )
Argument
- expr
 - A valid scalar, vector, or matrix expression.
 
Example
| Templex Expression | Result | 
|---|---|
{median(6)} | 
                                6 | 
                            
{median( {1, 4, 9, 16, 25} )} | 
                                9 | 
                            
{median( {1, 9, 16, 4, 25, 36} )} | 
                                12.5 | 
                            
                                    
                                 | 
                                3 | 
{median( { {1, 0}, {0, 1} } )} | 
                                0.5 | 
Comments
If expr is a scalar, the result is that value.
If expr is a vector or matrix with an odd number of elements, the result is a scalar that is the element at the center of the ordered vector (element (N+1)/2, where N is the number of elements).
If expr is a vector or matrix with an even number of elements, the result is a scalar that is the average value of the two elements closest to the center of the ordered vector (elements N/2 and (N+1)/2, where N is the number of elements).