nansum
Returns vector or matrix element sums, ignoring NaN values.
Syntax
R = nansum(A)
R = nansum(A,dim)
Inputs
- A
- The argument from which to sum elements.
- dim
- The dimension on which to sum, or 'all'
Outputs
- R
- The sums of non-NaN elements.
Examples
Vector:
R = nansum([1,2,3,nan])
R = 6
Matrix with a specified dimension:
R = nansum([1,2,3,nan;4,nan,5,6],2)
R = [Matrix] 2 x 1
6
15
Matrix with all dimensions:
R = nansum([1,2,3,nan;4,nan,5,6],'all')
R = 21