quantile
Quantiles of data set
Syntax
Description
returns quantiles of elements in input data Q
= quantile(A
,p
)A
for the cumulative
probability or probabilities p
in the interval [0,1].
If
A
is a vector, thenQ
is a scalar or a vector with the same length asp
.Q(i)
contains thep(i)
quantile.If
A
is a matrix, thenQ
is a row vector or a matrix, where the number of rows ofQ
is equal tolength(p)
. Thei
th row ofQ
contains thep(i)
quantiles of each column ofA
.If
A
is a multidimensional array, thenQ
contains the quantiles computed along the first array dimension whose size does not equal 1.
returns quantiles for Q
= quantile(A
,n
)n
evenly spaced cumulative probabilities
(1/(n
+ 1), 2/(n
+ 1), ...,
n
/(n
+ 1)) for integer n
> 1.
If
A
is a vector, thenQ
is a scalar or a vector with lengthn
.If
A
is a matrix, thenQ
is a matrix withn
rows.If
A
is a multidimensional array, thenQ
contains the quantiles computed along the first array dimension whose size does not equal 1.
returns
quantiles of all the elements of Q
= quantile(___,"all")A
for either of the first two
syntaxes.
operates along the dimension Q
= quantile(___,dim
)dim
for either of the first two syntaxes.
For example, if A
is a matrix, then quantile(A,p,2)
operates on the elements in each row.
operates along the dimensions specified in the vector Q
= quantile(___,vecdim
)vecdim
for either
of the first two syntaxes. For example, if A
is a matrix, then
quantile(A,n,[1 2])
operates on all the elements of
A
because every element of a matrix is contained in the array slice
defined by dimensions 1 and 2.
Examples
Input Arguments
More About
Algorithms
For an n-element vector A
, the
quantile
function computes quantiles by using a sorting-based algorithm
when you choose any method except "approximate"
.
The sorted elements in
A
are mapped to quantiles based on the method you choose, as described in this table.Quantile Method
"midpoint"
Before R2025a:
"exact"
"inclusive"
(since R2025a)"exclusive"
(since R2025a)Quantile of 1st sorted element 1/(2n) 0 1/(n+1) Quantile of 2nd sorted element 3/(2n) 1/(n−1) 2/(n+1) Quantile of 3rd sorted element 5/(2n) 2/(n−1) 3/(n+1) ... ... ... ... Quantile of kth sorted element (2k−1)/(2n) (k−1)/(n−1) k/(n+1) ... ... ... ... Quantile of (n−1)th sorted element (2n−3)/(2n) (n−2)/(n−1) (n−1)/(n+1) Quantile of nth sorted element (2n−1)/(2n) 1 n/(n+1) For example, if
A
is[6 3 2 10 1]
, then the quantiles are as shown in this table.Quantile Method
"midpoint"
Before R2025a:
"exact"
"inclusive"
(since R2025a)"exclusive"
(since R2025a)Quantile of 1
1/10 0 1/6 Quantile of 2
3/10 1/4 1/3 Quantile of 3
1/2 1/2 1/2 Quantile of 6
7/10 3/4 2/3 Quantile of 10
9/10 1 5/6 The
quantile
function uses linear interpolation to compute quantiles for probabilities between that of the first and that of the last sorted element ofA
. For more information, see Linear Interpolation.For example, if
A
is[6 3 2 10 1]
, then:For the midpoint method, the 0.4th quantile is
2.5
.Before R2025a: For the exact method, the 0.4th quantile is
2.5
.For the inclusive method, the 0.4th quantile is
2.6
. (since R2025a)For the exclusive method, the 0.4th quantile is
2.4
. (since R2025a)
The
quantile
function assigns the minimum or maximum values of the elements inA
to the quantiles corresponding to the probabilities outside of that range.For example, if
A
is[6 3 2 10 1]
, then, for both the midpoint and exclusive method, the 0.05th quantile is1
. (since R2025a)Before R2025a: For example, if
A
is[6 3 2 10 1]
, then, for the exact method, the 0.05th quantile is1
.
The quantile
function treats NaN
values as missing
values and removes them.
References
[1] Langford, E. “Quartiles in Elementary Statistics”, Journal of Statistics Education. Vol. 14, No. 3, 2006.