# iqr

Interquartile range of data set

## Syntax

``r = iqr(A)``
``r = iqr(A,"all")``
``r = iqr(A,dim)``
``r = iqr(A,vecdim)``

## Description

example

````r = iqr(A)` returns the interquartile range values of elements in input data `A`. If `A` is a vector, then `r` is the difference between the 75th and the 25th percentiles of the data contained in `A`.If `A` is a matrix, then `r` is a row vector containing the difference between the 75th and the 25th percentiles of the sample data in each column of `A`.If `A` is a multidimensional array, then `r` contains the interquartile range values computed along the first array dimension of size greater than 1. The size of this dimension is 1 while the sizes of all other dimensions remain the same as the input data. ```

example

````r = iqr(A,"all")` returns the interquartile range values of all the elements in `A`.```

example

````r = iqr(A,dim)` operates along the dimension `dim`. For example, if `A` is a matrix, then `iqr(A,2)` operates on the elements in each row.```

example

````r = iqr(A,vecdim)` operates along the dimensions specified in the vector `vecdim`. For example, if `A` is a matrix, then `iqr(A,[1 2])` operates on all the elements of `A` because every element of a matrix is contained in the array slice defined by dimensions 1 and 2.```

## Examples

collapse all

Generate a 4-by-4 matrix of normally distributed random data.

```rng default % for reproducibility A = randn(4,4)```
```A = 4×4 0.5377 0.3188 3.5784 0.7254 1.8339 -1.3077 2.7694 -0.0631 -2.2588 -0.4336 -1.3499 0.7147 0.8622 0.3426 3.0349 -0.2050 ```

Compute the interquartile range for each column of data.

`r = iqr(A)`
```r = 1×4 2.2086 1.2013 2.5969 0.8541 ```

Compute the interquartile range for each row of data.

`r2 = iqr(A,2)`
```r2 = 4×1 1.7237 2.9870 1.9449 1.8797 ```

Compute the interquartile range of a multidimensional array over multiple dimensions by specifying the "`all"` or `vecdim` input.

Create a 3-by-4-by-2 array.

`A = reshape(1:24,[3 4 2])`
```A = A(:,:,1) = 1 4 7 10 2 5 8 11 3 6 9 12 A(:,:,2) = 13 16 19 22 14 17 20 23 15 18 21 24 ```

Compute the interquartile range of all the values in `A`.

`rall = iqr(A,"all")`
```rall = 12 ```

Compute the interquartile range of each page of `A`. Specify the first and second dimensions as the operating dimensions along which the interquartile range is calculated.

`rPage = iqr(A,[1 2])`
```rPage = rPage(:,:,1) = 6 rPage(:,:,2) = 6 ```

`rPage(1,1,1)` is the interquartile range of all the elements in `A(:,:,1)`.

Compute the interquartile range of the elements in each `A(i,:,:)` slice by specifying the second and third dimensions as the operating dimensions.

`rRow = iqr(A,[2 3])`
```rRow = 3×1 12 12 12 ```

`rRow(3)` is the interquartile range of all the elements in `A(3,:,:)`.

## Input Arguments

collapse all

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

Data Types: `single` | `double`

Dimension to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension of size greater than 1.

Consider an input matrix `A`:

• `r = iqr(A,1)` computes the interquartile range of the columns in `A`. Because 1 is the specified operating dimension, `r` has a number of rows equal to the number of columns in `A`.

• `r = iqr(A,2)` computes the interquartile range of the rows in `A`. Because 2 is the specified operating dimension, `r` has a number of columns equal to the number of rows in `A`.

Dimension `dim` indicates the dimension of `r` whose length reduces to 1. The `size(r,dim)` is 1, while the sizes of all other dimensions of output `r` remain the same as the input data.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

Vector of dimensions to operate along, specified as a vector of positive integers. Each element represents a dimension of the input data.

The size of the output `r` in the specified operating dimensions is 1. The length of `r` in all other dimensions remains the same as the input data.

Consider a 2-by-3-by-3 input array, `A`. ```iqr(A,[1 2])``` returns a 1-by-1-by-3 array because 1 and 2 are the operating dimensions. Each page of the output array contains the interquartile range of the elements on the corresponding page of `A`.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

## Version History

Introduced before R2006a

expand all