Warning, /verification/tutorial_global_oce_latlon/diags_matlab/nanmean.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 = nanmean(x)
0002 %NANMEAN Average or mean ignoring NaNs.
0003 % NANMEAN(X) returns the average treating NaNs as missing values.
0004 % For vectors, NANMEAN(X) is the mean value of the non-NaN
0005 % elements in X. For matrices, NANMEAN(X) is a row vector
0006 % containing the mean value of each column, ignoring NaNs.
0007 %
0008 % See also NANMEDIAN, NANSTD, NANMIN, NANMAX, NANSUM.
0009
0010 % Copyright 1993-2000 The MathWorks, Inc.
0011 %
0012 if isempty(x) % Check for empty input.
0013 y = NaN;
0014 return
0015 end
0016
0017 % Replace NaNs with zeros.
0018 nans = isnan(x);
0019 i = find(nans);
0020 x(i) = zeros(size(i));
0021
0022 if min(size(x))==1,
0023 count = length(x)-sum(nans);
0024 else
0025 count = size(x,1)-sum(nans);
0026 end
0027
0028 % Protect against a column of all NaNs
0029 i = find(count==0);
0030 count(i) = ones(size(i));
0031 y = sum(x)./count;
0032 y(i) = i + NaN;