quantile
Quantiles of a sample.
Category: Data Import and Analysis > Descriptive Statistics
Syntax
Y = quantile(X, p)
Quantiles p (from 0 to 1) of the vector X, or of each column of a matrix.
Y = quantile(X, p, dim)
Along dimension dim.
Description
The quantile for probability p is the value below which a fraction p of the data lie. quantile(X, 0.5) is the median, and p = 0.25, 0.75 give the quartiles. Between observations the function interpolates linearly, treating the sorted values as the midpoints of equal probability bins; below the first and above the last midpoint it returns the minimum and maximum.
Quantiles describe the distribution without assuming a shape, and are resistant to outliers.
Input arguments
X- Numeric vector or matrix.
p- Cumulative probabilities between 0 and 1, scalar or vector.
dim- Dimension to operate along.
Output arguments
Y- The requested quantiles.
Example
Quartiles of a matrix
x = [3 1 4 1 5 9 2 6 5 3];
quantile(x, [0.25 0.5 0.75])
A = [1 5; 3 2; 4 9];
quantile(A, 0.5, 2)
Output
ans = 1×3
2.0000 3.5000 5.0000
ans = 3×1
3.0000
2.5000
6.5000