Statistics Toolbox | ![]() ![]() |
Functions for Data with Missing Values (NaNs)
Most real-world data sets have one or more missing elements. It is convenient to code missing entries in a matrix as NaN
(Not a Number).
Any arithmetic operation that involves the missing values in this matrix yields NaN
, as below.
Removing cells with NaN
would destroy the matrix structure. Removing whole rows that contain NaN
would discard real data. Instead, the Statistics Toolbox has a variety of functions that are similar to other MATLAB functions, but that treat NaN
values as missing and therefore ignore them in the calculations.
nansum(m) ans = 7 10 13
NaN Functions | |
nanmax |
Maximum ignoring NaN s |
nanmean |
Mean ignoring NaN s |
nanmedian |
Median ignoring NaN s |
nanmin |
Minimum ignoring NaN s |
nanstd |
Standard deviation ignoring NaN s |
nansum |
Sum ignoring NaN s |
In addition, other Statistics Toolbox functions operate only on the numeric values, ignoring NaN
s. These include iqr
, kurtosis
, mad
, prctile
, range
, skewness
, and trimmean
.
![]() | Measures of Dispersion | Function for Grouped Data | ![]() |