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
Ais a vector, thenPis a scalar or a vector with the same length asp.P(i)contains thep(i)percentile.If
Ais a matrix, thenPis a row vector or a matrix, where the number of rows ofPis equal tolength(p). Theith row ofPcontains thep(i)percentiles of each column ofA.If
Ais a multidimensional array, thenPcontains 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
Aare 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
Ais[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 110 0 50/3 Percentile of 230 25 100/3 Percentile of 350 50 50 Percentile of 670 75 200/3 Percentile of 1090 100 250/3 The
prctilefunction 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
Ais[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
prctilefunction assigns the minimum or maximum values of the elements inAto the percentiles corresponding to the percentages outside of that range.For example, if
Ais[6 3 2 10 1], then, for both the midpoint and exclusive method, the 5th percentile is1. (since R2025a)Before R2025a: For example, if
Ais[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.
