prctile
Percentiles of data set
Syntax
Description
P = prctile(A,p)A for the percentages
          p in the interval [0,100].
- If - Ais a vector, then- Pis a scalar or a vector with the same length as- p.- P(i)contains the- p(i)percentile.
- If - Ais a matrix, then- Pis a row vector or a matrix, where the number of rows of- Pis equal to- length(p). The- ith row of- Pcontains the- p(i)percentiles of each column of- A.
- If - Ais a multidimensional array, then- Pcontains 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 - 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 - prctilefunction uses linear interpolation to compute percentiles for percentages between that of the first and that of the last sorted element of- A. 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 in- Ato 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 is- 1. (since R2025a)- Before R2025a: For example, if - Ais- [6 3 2 10 1], then, for the exact method, the 5th percentile is- 1.
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.
