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
y = nansum(X)sum of the elements of
        X, computed after removing all NaN values.
- If - Xis a vector, then- nansum(X)is the sum of all the non-- NaNelements of- X.
- If - Xis a matrix, then- nansum(X)is a row vector of column sums, computed after removing- NaNvalues.
- If - Xis a multidimensional array, then- nansumoperates along the first nonsingleton dimension of- X. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same.- nansumremoves all- NaNvalues.
For information on how nansum treats arrays of all
          NaN values, see Tips.
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 all- NaNvalues, the array is empty once the- NaNvalues are removed and, therefore, the sum of the remaining elements is- 0. The output- 0is not a sum of- NaNvalues.
