matlab sum nan,matlab中Undefined function 'nansum' for input arguments of type 'double'.

满意答案

nansum 是统计工具箱(Statistics Toolbox)里面的函数,请确认是否安装了该工具箱。

如果不想装工具箱,我把函数的代码给你,可以独立使用(不过最好还是安装工具箱):

nansum.mfunction y = nansum(x,dim)

%NANSUM Sum, ignoring NaNs.

%   Y = NANSUM(X) returns the sum of X, treating NaNs as missing values.

%   For vector input, Y is the sum of the non-NaN elements in X.  For

%   matrix input, Y is a row vector containing the sum of non-NaN elements

%   in each column.  For N-D arrays, NANSUM operates along the first

%   non-singleton dimension.

%

%   Y = NANSUM(X,DIM) takes the sum along dimension DIM of X.

%

%   See also SUM, NANMEAN, NANVAR, NANSTD, NANMIN, NANMAX, NANMEDIAN.

%   Copyright 1993-2004 The MathWorks, Inc.

%   $Revision: 2.10.2.4 $  $Date: 2004/07/28 04:38:44 $

% Find NaNs and set them to zero.  Then sum up non-NaNs.  Cols of all NaNs

% will return zero.

x(isnan(x)) = 0;

if nargin == 1 % let sum figure out which dimension to work along

y = sum(x);

else           % work along the explicitly given dimension

y = sum(x,dim);

end

nanmean.mfunction m = nanmean(x,dim)

%NANMEAN Mean value, ignoring NaNs.

%   M = NANMEAN(X) returns the sample mean of X, treating NaNs as missing

%   values.  For vector input, M is the mean value of the non-NaN elements

%   in X.  For matrix input, M is a row vector containing the mean value of

%   non-NaN elements in each column.  For N-D arrays, NANMEAN operates

%   along the first non-singleton dimension.

%

%   NANMEAN(X,DIM) takes the mean along dimension DIM of X.

%

%   See also MEAN, NANMEDIAN, NANSTD, NANVAR, NANMIN, NANMAX, NANSUM.

%   Copyright 1993-2004 The MathWorks, Inc.

%   $Revision: 2.13.4.3 $  $Date: 2004/07/28 04:38:41 $

% Find NaNs and set them to zero

nans = isnan(x);

x(nans) = 0;

if nargin == 1 % let sum deal with figuring out which dimension to use

% Count up non-NaNs.

n = sum(~nans);

n(n==0) = NaN; % prevent divideByZero warnings

% Sum up non-NaNs, and divide by the number of non-NaNs.

m = sum(x) ./ n;

else

% Count up non-NaNs.

n = sum(~nans,dim);

n(n==0) = NaN; % prevent divideByZero warnings

% Sum up non-NaNs, and divide by the number of non-NaNs.

m = sum(x,dim) ./ n;

end追问: 谢谢你!请问怎么安装工具箱呢?我百度了一下好多工具箱啊……这个具体属于哪个的工具箱呢?麻烦你了

我搜索到应该是统计学的工具箱,安装后help语句中出现了这个函数,可以在运算的时候还是有问题啊

追答:你是说help能查到,但运算时报错?那有可能是财经工具箱(Financial Toolbox)的同名函数,但那个函数是对fints对象重载的。你试试执行命令which nansum -all然后贴出结果来。

追问: 谢谢你啦……最后我重新下载安装了2012a就可以运行了。麻烦你了!

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值