nansum for double or single -> why error?

hi :)
can please someone explain to me how I can use nansum for a vector? I always get this error:
Undefined function 'nansum' for input arguments of type 'single'.
same for double >> in what datatype do I have to transform the data?
Thx for ur help.

 採用された回答

Cedric
Cedric 2015 年 7 月 28 日
編集済み: Cedric 2015 年 7 月 28 日

0 投票

Are you using a version of MATLAB anterior to 2006a? Evaluate ver or version to check. Or maybe you shadowed the function by naming a variable nansum by mistake during your tests. To check, evaluate
which nansum
and see if you get something like
C:\Program Files\MATLAB\R2015b\toolbox\stats\stats\nansum.m

3 件のコメント

Marco Bergamin
Marco Bergamin 2015 年 7 月 28 日
... thx didn't know that this function requires a toolbox licence :S
C:\Program Files\MATLAB\R2015a\toolbox\stats\stats\nansum.m % Has no license available
Cedric
Cedric 2015 年 7 月 28 日
編集済み: Cedric 2015 年 7 月 28 日
Ok, we can help you implement something similar "by hand" if you need (?)
Cedric
Cedric 2015 年 7 月 28 日
編集済み: Cedric 2015 年 7 月 28 日
Well, here is one way to do it:
function s = nansum( A, varargin )
A(isnan( A )) = 0 ;
s = sum( A, varargin{:} ) ;
end

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2015 年 7 月 28 日

1 投票

Marco, since you're using release R2015a (according to your comment on Cedric's answer) you can use SUM with the appropriate nanflag input argument instead of NANSUM.
x = [1:10 NaN];
sum(x, 'omitnan')

3 件のコメント

Cedric
Cedric 2015 年 7 月 28 日
I had never realized that this flag was implemented, thank you for the update!
Steven Lord
Steven Lord 2015 年 7 月 28 日
Not only does SUM accept this flag, but so do a number of the other basic statistical calculation functions. For a full list, see the second item in the Mathematics section of the release R2015a Release Notes for MATLAB.
Cedric
Cedric 2015 年 7 月 28 日
Thank you Steven! I obviously don't spend enough time reading release notes.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

質問済み:

2015 年 7 月 28 日

コメント済み:

2015 年 7 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by