sum of an array

2 visualizaciones (últimos 30 días)
Bini Z
Bini Z el 9 de Sept. de 2016
Comentada: John D'Errico el 9 de Sept. de 2016
How do I get the sum of an array which contains some NaN. I am getting some error like this:
sum(a,'omitNaN')
??? Error using ==> sum
Trailing string input must be 'double' or 'native'.
a = Columns 1 through 5
NaN 664.7000 663.2000 662.2000 NaN
Columns 6 through 10
688.4000 688.4000 NaN NaN NaN
Columns 11 through 15
NaN NaN NaN NaN NaN
Columns 16 through 20
NaN NaN 731.4000 723.0000 704.8000
Also, when I am calculating mean and standard deviation, do i have to include NaN or omit it?
Thank you,

Respuesta aceptada

John D'Errico
John D'Errico el 9 de Sept. de 2016
Editada: John D'Errico el 9 de Sept. de 2016
If you want to use options in tools that work under current releases, you need to use a current release of MATLAB. At least you need to use something sufficiently recent that sum will include that option. Since the above computation works fine for me using R2016a, you are using an older release.
You can always use nansum from the stats toolbox, if you have that toolbox.
As far as computing the mean or standard deviation, again, either get a current release of MATLAB, or get the stats TB.
  3 comentarios
Image Analyst
Image Analyst el 9 de Sept. de 2016
I think John must have the Crystal Ball Toolbox.
John D'Errico
John D'Errico el 9 de Sept. de 2016
I'm usually not willing to use that toolbox, as it is only in beta release.
I've been thinking that a good change to answers might be to REQUIRE that you add your MATLAB release to a question when you submit that question. This would have immediately tipped us off to the problem. As it was, I decided to make an educated guess, and that was the only guess that made sense to me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by