/[MITgcm]/MITgcm/verification/tutorial_global_oce_latlon/diags_matlab/nanmean.m
ViewVC logotype

Contents of /MITgcm/verification/tutorial_global_oce_latlon/diags_matlab/nanmean.m

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


Revision 1.1 - (show annotations) (download)
Sat Aug 12 19:37:26 2006 UTC (17 years, 8 months ago) by jmc
Branch: MAIN
moved from verification/global_ocean.90x40x15/diags_matlab ;
 add Header and Name; use "quiver" instead of NaNquiver (<- not standard);

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 $ $Date: 2002/10/22 13:30:40 $
12 %
13 % $Header: $
14 % $Name: $
15
16 if isempty(x) % Check for empty input.
17 y = NaN;
18 return
19 end
20
21 % Replace NaNs with zeros.
22 nans = isnan(x);
23 i = find(nans);
24 x(i) = zeros(size(i));
25
26 if min(size(x))==1,
27 count = length(x)-sum(nans);
28 else
29 count = size(x,1)-sum(nans);
30 end
31
32 % Protect against a column of all NaNs
33 i = find(count==0);
34 count(i) = ones(size(i));
35 y = sum(x)./count;
36 y(i) = i + NaN;

  ViewVC Help
Powered by ViewVC 1.1.22