nansum.m

来自「不完全数据分析MATLAB程序(部分信息重建):最小均方估计、协方差矩阵、缺失值」· M 代码 · 共 24 行

M
24
字号
function y = nansum(x)%NANSUM   Sum ignoring NaNs.%%    NANSUM(X) returns the sum over non-NaN elements of X.  For%    vectors, NANSUM(X) is the sum of the non-NaN elements in X. For%    matrices, NANSUM(X) is a row vector containing the sum of the%    non-NaN elements in each column of X.%%    See also NANMEAN, NANSTD.  error(nargchk(1,1,nargin))          % check number of input arguments 				        % replace NaNs with zeros.  nans    = isnan(x);  inan    = find(nans);  x(inan) = zeros(size(inan));  y       = sum(x);    % protect against an entire column of NaNs  iall    = find(all(nans));  y(iall) = NaN;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?