Standard deviation ignoring NaN values
y = nanstd(X)
y = nanstd(X,1)
y = nanstd(X,flag,dim)
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.
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