nansum
(Not recommended) Sum, ignoring NaN values
nansum is not recommended. Use the MATLAB® function sum instead. With the sum function, you can specify whether
to include or omit NaN values for the calculation. For more information,
see Version History.
Description
returns the
y = nansum(X)sum of the elements of
X, computed after removing all NaN values.
If
Xis a vector, thennansum(X)is the sum of all the non-NaNelements ofX.If
Xis a matrix, thennansum(X)is a row vector of column sums, computed after removingNaNvalues.If
Xis a multidimensional array, thennansumoperates along the first nonsingleton dimension ofX. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.nansumremoves allNaNvalues.
For information on how nansum treats arrays of all
NaN values, see Tips.
returns the sum over the dimensions specified in the vector y = nansum(X,vecdim)vecdim. The
function computes the sums after removing NaN values. For example, if
X is a matrix, then nansum(X,[1 2]) is the sum of
all non-NaN elements of X because every element of a
matrix is contained in the array slice defined by dimensions 1 and 2.
Examples
Input Arguments
Output Arguments
Tips
When
nansumcomputes the sum of an array of allNaNvalues, the array is empty once theNaNvalues are removed and, therefore, the sum of the remaining elements is0. The output0is not a sum ofNaNvalues.
