/[MITgcm]/MITgcm_contrib/ESMF/global_ocean.128x64x15/diags_matlab/nansum.m
ViewVC logotype

Contents of /MITgcm_contrib/ESMF/global_ocean.128x64x15/diags_matlab/nansum.m

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


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Sun Feb 15 22:28:29 2004 UTC (21 years, 5 months ago) by cnh
Branch: MAIN, Initial
CVS Tags: adoption_1_0_pre_A, Baseline, HEAD
Changes since 1.1: +0 -0 lines
Initial checkin

1 function y = nansum(x)
2 %NANSUM Sum ignoring NaNs.
3 % NANSUM(X) returns the sum treating NaNs as missing values.
4 % For vectors, NANSUM(X) is the sum of the non-NaN elements in
5 % X. For matrices, NANSUM(X) is a row vector containing the sum
6 % of the non-NaN elements in each column of X.
7 %
8 % See also NANMEDIAN, NANSTD, NANMIN, NANMAX, NANMEAN.
9
10 % Copyright 1993-2000 The MathWorks, Inc.
11 % $Revision: 1.1 $ $Date: 2002/10/22 13:30:40 $
12
13 % Replace NaNs with zeros.
14 nans = isnan(x);
15 i = find(nans);
16 x(i) = zeros(size(i));
17
18 % Protect against an entire column of NaNs
19 y = sum(x);
20 i = find(all(nans));
21 y(i) = i + NaN;
22

  ViewVC Help
Powered by ViewVC 1.1.22