Percentiles of a data set

returns percentiles of the elements in a data vector or array `Y`

= prctile(`X`

,`p`

)`X`

for the
percentages `p`

in the interval [0,100].

If

`X`

is a vector, then`Y`

is a scalar or a vector with the same length as the number of percentiles requested (`length(p)`

).`Y(i)`

contains the`p(i)`

percentile.If

`X`

is a matrix, then`Y`

is a row vector or a matrix, where the number of rows of`Y`

is equal to the number of percentiles requested (`length(p)`

). The`i`

th row of`Y`

contains the`p(i)`

percentiles of each column of`X`

.For multidimensional arrays,

`prctile`

operates along the first nonsingleton dimension of`X`

.

returns percentiles over the dimensions specified in the vector `Y`

= prctile(`X`

,`p`

,`vecdim`

)`vecdim`

.
For example, if `X`

is a matrix, then ```
prctile(X,50,[1
2])
```

returns the 50th percentile of all the elements of `X`

because every element of a matrix is contained in the array slice defined by dimensions 1
and 2.

For an *n*-element vector `X`

, `prctile`

returns percentiles by using a sorting-based algorithm as follows:

The sorted elements in

`X`

are taken as the 100(0.5/*n*)th, 100(1.5/*n*)th, ..., 100([*n*– 0.5]/*n*)th percentiles. For example:For a data vector of five elements such as {6, 3, 2, 10, 1}, the sorted elements {1, 2, 3, 6, 10} respectively correspond to the 10th, 30th, 50th, 70th, and 90th percentiles.

For a data vector of six elements such as {6, 3, 2, 10, 8, 1}, the sorted elements {1, 2, 3, 6, 8, 10} respectively correspond to the (50/6)th, (150/6)th, (250/6)th, (350/6)th, (450/6)th, and (550/6)th percentiles.

`prctile`

uses linear interpolation to compute percentiles for percentages between 100(0.5/*n*) and 100([*n*– 0.5]/*n*).`prctile`

assigns the minimum or maximum values of the elements in`X`

to the percentiles corresponding to the percentages outside that range.

`prctile`

treats `NaN`

s
as missing values and removes them.

[1] Langford, E. “Quartiles in
Elementary Statistics”, *Journal of Statistics Education*. Vol.
14, No. 3, 2006.