# iqr

Interquartile range

## Description

example

r = iqr(x) returns the interquartile range of the values in x.

example

r = iqr(x,dim) returns the interquartile range along the dimension of x specified by dim.

example

r = iqr(pd) returns the interquartile range of the probability distribution, pd.

## Examples

collapse all

### Compute the Interquartile Range

Generate a 4-by-4 matrix of random data from a normal distribution with parameter values equal to 10 and equal to 1.

rng default  % For reproducibility
x = normrnd(10,1,4)
x =

10.5377   10.3188   13.5784   10.7254
11.8339    8.6923   12.7694    9.9369
7.7412    9.5664    8.6501   10.7147
10.8622   10.3426   13.0349    9.7950

Compute the interquartile range for each column of data.

r = iqr(x)
r =

2.2086    1.2013    2.5969    0.8541

Compute the interquartile range for each row of data.

r2 = iqr(x,2)
r2 =

1.7237
2.9870
1.9449
1.8797

### Compute the Normal Distribution Interquartile Range

Create a standard normal distribution object with the mean, , equal to 0 and the standard deviation, , equal to 1.

pd = makedist('Normal',0,1);

Compute the interquartile range of the standard normal distribution.

r = iqr(pd)
r =

1.3490

The returned value is the difference between the 75th and the 25th percentile values for the distribution. This is equivalent to computing the difference between the inverse cumulative distribution function (icdf) values at the probabilities y equal to 0.75 and 0.25.

r2 = icdf(pd,0.75) - icdf(pd,0.25)
r2 =

1.3490

## Input Arguments

collapse all

### x — Input arrayvector | matrix | multidimensional array

Input array, specified as a vector, matrix, or multidimensional array.

Data Types: single | double

### dim — Dimension1 (default) | positive integer value

Dimension along which the interquartile range is calculated, specified as a positive integer. For example, for a matrix x, when dim is equal to 1, iqr returns the interquartile range for the columns of x. When dim is equal to 2, iqr returns the interquartile range for the rows of x. For n-dimensional arrays, iqr operates along the first nonsingleton dimension of X.

Data Types: single | double

### pd — Probability distributionprobability distribution object

Probability distribution, specified as a probability distribution object created using one of the following.

 makedist Create a probability distribution object using specified parameter values. fitdist Fit a probability distribution object to sample data. dfittool Fit a probability distribution object to sample data using the interactive Distribution Fitting app. paretotails Create a Pareto tails object. gmdistribution Create a Gaussian mixture distribution object.

## Output Arguments

collapse all

### r — Interquartile rangescalar value

Interquartile range, returned as a scalar value.

• If you input a vector for x, then r is the difference between the 75th and the 25th percentiles of the sample data contained in x.

• If you input a matrix for x, then r is a row vector containing the difference between the 75th and the 25th percentiles of the sample data contained each column of x.

• If you input a probability distribution, pd, then the value of r is the difference between the values of the 75th and 25th percentile of the probability distribution.