Warning, /verification/tutorial_global_oce_latlon/diags_matlab/nansum.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
051ee7f715 Jean*0001 function y = nansum(x)
0002 %NANSUM Sum ignoring NaNs.
0003 % NANSUM(X) returns the sum treating NaNs as missing values.
0004 % For vectors, NANSUM(X) is the sum of the non-NaN elements in
0005 % X. For matrices, NANSUM(X) is a row vector containing the sum
0006 % of the non-NaN elements in each column of X.
0007 %
0008 % See also NANMEDIAN, NANSTD, NANMIN, NANMAX, NANMEAN.
0009
0010 % Copyright 1993-2000 The MathWorks, Inc.
0011 %
0012 % Replace NaNs with zeros.
0013 nans = isnan(x);
0014 i = find(nans);
0015 x(i) = zeros(size(i));
0016
0017 % Protect against an entire column of NaNs
0018 y = sum(x);
0019 i = find(all(nans));
0020 y(i) = i + NaN;
0021