prctile
Percentiles of data set
Syntax
Description
returns percentiles of elements in input data P
= prctile(A
,p
)A
for the percentages
p
in the interval [0,100].
If
A
is a vector, thenP
is a scalar or a vector with the same length asp
.P(i)
contains thep(i)
percentile.If
A
is a matrix, thenP
is a row vector or a matrix, where the number of rows ofP
is equal tolength(p)
. Thei
th row ofP
contains thep(i)
percentiles of each column ofA
.If
A
is a multidimensional array, thenP
contains the percentiles computed along the first array dimension whose size does not equal 1.
Examples
Input Arguments
More About
Algorithms
For an n-element vector A
, the
prctile
function computes percentiles by using a sorting-based
algorithm when you choose any method except "approximate"
.
The sorted elements in
A
are mapped to percentiles based on the method you choose, as described in this table.Percentile Method
"midpoint"
Before R2025a:
"exact"
"inclusive"
(since R2025a)"exclusive"
(since R2025a)Percentile of 1st sorted element 50/n 0 100/(n+1) Percentile of 2nd sorted element 150/n 100/(n−1) 200/(n+1) Percentile of 3rd sorted element 250/n 200/(n−1) 300/(n+1) ... ... ... ... Percentile of kth sorted element 50(2k−1)/n 100(k−1)/(n−1) 100k/(n+1) ... ... ... ... Percentile of (n−1)th sorted element 50(2n−3)/n 100(n−2)/(n−1) 100(n−1)/(n+1) Percentile of nth sorted element 50(2n−1)/n 100 100n/(n+1) For example, if
A
is[6 3 2 10 1]
, then the percentiles are as shown in this table.Percentile Method
"midpoint"
Before R2025a:
"exact"
"inclusive"
(since R2025a)"exclusive"
(since R2025a)Percentile of 1
10 0 50/3 Percentile of 2
30 25 100/3 Percentile of 3
50 50 50 Percentile of 6
70 75 200/3 Percentile of 10
90 100 250/3 The
prctile
function uses linear interpolation to compute percentiles for percentages 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 40th percentile is
2.5
.Before R2025a: For the exact method, the 40th percentile is
2.5
.For the inclusive method, the 40th percentile is
2.6
. (since R2025a)For the exclusive method, the 40th percentile is
2.4
. (since R2025a)
The
prctile
function assigns the minimum or maximum values of the elements inA
to the percentiles corresponding to the percentages outside of that range.For example, if
A
is[6 3 2 10 1]
, then, for both the midpoint and exclusive method, the 5th percentile is1
. (since R2025a)Before R2025a: For example, if
A
is[6 3 2 10 1]
, then, for the exact method, the 5th percentile is1
.
The prctile
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.