sum of an array
2 ビュー (過去 30 日間)
古いコメントを表示
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,
0 件のコメント
採用された回答
John D'Errico
2016 年 9 月 9 日
編集済み: John D'Errico
2016 年 9 月 9 日
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 件のコメント
John D'Errico
2016 年 9 月 9 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!