# nanmin

(Not recommended) Minimum, ignoring `NaN` values

`nanmin` is not recommended. Use the MATLAB® function `min` instead. With the `min` function, you can specify whether to include or omit `NaN` values for the calculation. For more information, see Compatibility Considerations.

## Syntax

``y = nanmin(X)``
``y = nanmin(X,[],dim)``
``[y,indices] = nanmin(___)``
``y = nanmin(X,[],'all')``
``y = nanmin(X,[],vecdim)``
``Y = nanmin(X1,X2)``

## Description

````y = nanmin(X)` is the minimum `min` of `X`, computed after removing `NaN` values.For vectors `x`, `nanmin(x)` is the minimum of the remaining elements, once `NaN` values are removed. For matrices `X`, `nanmin(X)` is a row vector of column minima, once `NaN` values are removed. For multidimensional arrays `X`, `nanmin` operates along the first nonsingleton dimension.```
````y = nanmin(X,[],dim)` operates along the dimension `dim` of `X`.```

example

````[y,indices] = nanmin(___)` also returns the row indices of the minimum values for each column in the vector `indices`.```

example

````y = nanmin(X,[],'all')` returns the minimum of all elements of `X`, computed after removing `NaN` values.```
````y = nanmin(X,[],vecdim)` returns the minimum over the dimensions specified in the vector `vecdim`, computed after removing `NaN` values. Each element of `vecdim` represents a dimension of the input array `X`. The output `y` has length 1 in the specified operating dimensions. The other dimension lengths are the same for `X` and `y`. For example, if `X` is a 2-by-3-by-4 array, then `nanmin(X,[],[1 2])` returns a 1-by-1-by-4 array. Each element of the output array is the minimum of the elements on the corresponding page of `X`.```
````Y = nanmin(X1,X2)` returns an array `Y` the same size as `X1` and `X2` with ```Y(i,j) = nanmin(X1(i,j),X2(i,j))```. Scalar inputs are expanded to an array of the same size as the other input.```

## Examples

collapse all

Find the column minimum values and their indices for matrix data with missing values.

```X = magic(3); X([1 6:9]) = NaN```
```X = 3×3 NaN 1 NaN 3 5 NaN 4 NaN NaN ```
`[y,indices] = nanmin(X)`
```y = 1×3 3 1 NaN ```
```indices = 1×3 2 1 1 ```

Find the minimum of all the values in an array, ignoring missing values.

Create a 2-by-5-by-3 array `X` with some missing values.

```X = reshape(1:30,[2 5 3]); X([10:12 25]) = NaN```
```X = X(:,:,1) = 1 3 5 7 9 2 4 6 8 NaN X(:,:,2) = NaN 13 15 17 19 NaN 14 16 18 20 X(:,:,3) = 21 23 NaN 27 29 22 24 26 28 30 ```

Find the minimum of the elements of `X`.

`y = nanmin(X,[],'all')`
```y = 1 ```

## Version History

Introduced before R2006a

collapse all

### R2020b: `nanmin` is not recommended

`nanmin` is not recommended. Use the MATLAB function `min` instead. There are no plans to remove `nanmin`.

To update your code, change instances of the function name `nanmin` to `min`. You do not need to change the input arguments. If you want to include `NaN` values, then specify the `'includenan'` option for the `nanflag` input argument.

The `min` function has these advantages over the `nanmin` function:

• `min` offers more extended capabilities for supporting tall arrays, GPU arrays, distribution arrays, C/C++ code generation, and GPU code generation.

• When you specify the `'linear'` option, `min` returns the linear index into the input array that corresponds to the minimum value.