nansum for double or single -> why error?

2 Ansichten (letzte 30 Tage)
Marco Bergamin
Marco Bergamin am 28 Jul. 2015
Kommentiert: Cedric am 28 Jul. 2015
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.

Akzeptierte Antwort

Cedric
Cedric am 28 Jul. 2015
Bearbeitet: Cedric am 28 Jul. 2015
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 Kommentare
Cedric
Cedric am 28 Jul. 2015
Bearbeitet: Cedric am 28 Jul. 2015
Ok, we can help you implement something similar "by hand" if you need (?)
Cedric
Cedric am 28 Jul. 2015
Bearbeitet: Cedric am 28 Jul. 2015
Well, here is one way to do it:
function s = nansum( A, varargin )
A(isnan( A )) = 0 ;
s = sum( A, varargin{:} ) ;
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord
Steven Lord am 28 Jul. 2015
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 Kommentare
Steven Lord
Steven Lord am 28 Jul. 2015
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 am 28 Jul. 2015
Thank you Steven! I obviously don't spend enough time reading release notes.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by