/[MITgcm]/MITgcm_contrib/ESMF/global_ocean.128x60x15/diags_matlab/nanmean.m
ViewVC logotype

Contents of /MITgcm_contrib/ESMF/global_ocean.128x60x15/diags_matlab/nanmean.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Tue Mar 30 03:58:59 2004 UTC (20 years, 2 months ago) by cnh
Branch: MAIN
CVS Tags: adoption_1_0_pre_A, HEAD
New test with different size

1 function y = nanmean(x)
2 %NANMEAN Average or mean ignoring NaNs.
3 % NANMEAN(X) returns the average treating NaNs as missing values.
4 % For vectors, NANMEAN(X) is the mean value of the non-NaN
5 % elements in X. For matrices, NANMEAN(X) is a row vector
6 % containing the mean value of each column, ignoring NaNs.
7 %
8 % See also NANMEDIAN, NANSTD, NANMIN, NANMAX, NANSUM.
9
10 % Copyright 1993-2000 The MathWorks, Inc.
11 % $Revision: 1.1.1.1 $ $Date: 2004/02/15 22:28:30 $
12
13 if isempty(x) % Check for empty input.
14 y = NaN;
15 return
16 end
17
18 % Replace NaNs with zeros.
19 nans = isnan(x);
20 i = find(nans);
21 x(i) = zeros(size(i));
22
23 if min(size(x))==1,
24 count = length(x)-sum(nans);
25 else
26 count = size(x,1)-sum(nans);
27 end
28
29 % Protect against a column of all NaNs
30 i = find(count==0);
31 count(i) = ones(size(i));
32 y = sum(x)./count;
33 y(i) = i + NaN;

  ViewVC Help
Powered by ViewVC 1.1.22