📄 nansum.m
字号:
function y = nansum(x,dim)% FORMAT: Y = NANSUM(X,DIM)% % Sum of values ignoring NaNs%% This function enhances the functionality of NANSUM as distributed in% the MATLAB Statistics Toolbox and is meant as a replacement (hence the% identical name). %% NANSUM(X,DIM) calculates the mean along any dimension of the N-D array% X ignoring NaNs. If DIM is omitted NANSUM averages along the first% non-singleton dimension of X.%% Similar replacements exist for NANMEAN, NANSTD, NANMEDIAN, NANMIN, and% NANMAX which are all part of the NaN-suite.%% See also SUM% -------------------------------------------------------------------------% author: Jan Gl鋝cher% affiliation: Neuroimage Nord, University of Hamburg, Germany% email: glaescher@uke.uni-hamburg.de% % $Revision: 1.2 $ $Date: 2005/06/13 12:14:38 $% This file is distributed with the GPLAB Toolbox (sara@dei.uc.pt)if isempty(x) y = []; returnendif nargin < 2 dim = min(find(size(x)~=1)); if isempty(dim) dim = 1; endend% Replace NaNs with zeros.nans = isnan(x);x(isnan(x)) = 0; % Protect against a all NaNs in one dimensioncount = size(x,dim) - sum(nans,dim);i = find(count==0);y = sum(x,dim);y(i) = NaN;% $Id: nansum.m,v 1.2 2005/06/13 12:14:38 glaescher Exp glaescher $
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -