Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

nanstd

Standard deviation ignoring NaN values

Syntax

y = nanstd(X)
y = nanstd(X,1)
y = nanstd(X,flag,dim)

Description

y = nanstd(X) is the standard deviation std of X, computed after removing NaN values.

For vectors x, nanstd(x) is the sample standard deviation of the remaining elements, once NaN values are removed. For matrices X, nanstd(X) is a row vector of column sample standard deviations, once NaN values are removed. For multidimensional arrays X, nanstd operates along the first nonsingleton dimension.

If n is the number of remaining observations after removing observations with NaN values, nanstd normalizes y by n–1. To specify normalization by n, use y = nanstd(X,1).

y = nanstd(X,flag,dim) takes the standard deviation along the dimension dim of X. The flag is 0 or 1 to specify normalization by n – 1 or n, respectively, where n is the number of remaining observations after removing observations with NaN values.

Examples

Find column standard deviations for data with missing values:

X = magic(3);
X([1 6:9]) = repmat(NaN,1,5)
X =
   NaN     1   NaN
     3     5   NaN
     4   NaN   NaN
y = nanstd(X)
y =
   0.7071  2.8284  NaN

Alternative Functionality

Instead of using nanstd, you can use the MATLAB® function std with the input argument nanflag specified as the value 'omitnan'.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

| | |

Introduced before R2006a

Was this topic helpful?