# MATLAB Quantile

This tutorial will discuss computing the quantiles of the binomial distribution, standard normal distribution, and data sets using the `binoinv()`

, `norminv()`

, and `quantile()`

functions in MATLAB.

## MATLAB Quantiles of Distributions

A quantile represents a particular part of a distribution. These can be the values above and below a specific limit in a distribution.

For example, suppose we divide a distribution into certain parts. In that case, we can represent each part with a specific quantile, and each quantile or part of the distribution will have the same area or values inside it.

For example, if we divide a distribution into four parts, we will have four equal parts, and each part will cover 25 percent of the total area of the distribution. We can represent each part of the distribution in terms of quantiles.

MATLAB provides a built-in function to find a specific quantile of binomial and standard normal distribution. We can use the `binoinv()`

function to find the quantile of the binomial distribution and the `norminv()`

function to find the quantile of the standard normal distribution.

We must pass three inputs in each function to find the specific quantile. The first argument of the `binoinv()`

function is the quantile number, the second argument is the value of independent trials `N`

, and the fourth argument is the value of probability `P`

of success.

The three inputs of the `binoinv()`

function can be scalar, vector, matrices, or arrays of multiple dimensions, and all of them should have the same size. The second argument should be a positive integer, and the value of the other two arguments should be between 0 and 1.

The first argument of the `norminv()`

function is the quantile number, the second argument is the value of mean `mu`

, and the fourth argument is the value of standard deviation `sigma`

. We can still find the quantile value if we don’t pass the mean and standard deviation values.

By default, the `norminv()`

function will use 0 as the value of mean and 1 as the standard deviation value. For example, let’s find the quantile number `0.02`

of the binomial and normal distribution using the `binoinv()`

and `norminv()`

functions.

See the code below.

```
clc
clear
b = binoinv(0.02,50,0.3)
n = norminv(0.02,0,1)
```

Output:

```
b =
9
n =
-2.0537
```

In the above code, we used 50 as the value of independent trials `N`

and `0.3`

as the value of the probability of successful trials in the `binoinv()`

function. We used 0 as the value of the mean and 1 as the standard deviation value in the `norminv()`

function.

Check this link for more details about the `binoinv()`

function. And check this link for more details about the `norminv()`

function.

## MATLAB Quantiles of Data Sets

If we want to find the quantile of a data set, we can use MATLAB’s `quantile()`

function. The `quantile()`

function has 4 syntaxes which are given below.

```
Output = quantile(dataset,p)
Output = quantile(___,"all")
Output = quantile(___,dim)
Output = quantile(___,"Method",method)
```

The first syntax will return the quantiles of all the elements present in the input data set according to the probabilities defined by the variable `p`

. If the input data set is a vector, the output will be a scalar or a vector, and it will have the same length as the probability variable `p`

.

If the input data is a matrix, the output will be a vector or matrix, and the length of the probability variable `p`

will equal the rows of the output vector. If the input data set is a multidimensional array, the quantiles will be computed along the first dimension of the data set.

The second syntax will return all the quantiles of the given data set. The third syntax sets the dimension on which the quantiles will be computed.

By default, the function will operate on the first dimension of the matrix or multidimensional array; however, we can set it to other dimensions by defining the dimension number as the third argument in the `quantile()`

function. The fourth syntax is used to set the method used to compute the quantiles, which is set to the `exact`

method by default, but we can also set it to `approximate`

.

For example, let’s find the quantiles of a matrix using the `quantile()`

function. See the code below.

```
clc
clear
m = magic(2)
q = quantile(m,0.3)
```

Output:

```
m =
1 3
4 2
q =
1.3000 2.1000
```

In the above code, we used the `magic()`

function to create a 2-by-2 matrix. We can see in the output that the `quantile()`

function has computed the quantiles for each column.

Check this link for more details about the `quantile()`

function.