1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NaNを含むベクトルをsumする

Posted at

#したいこと

下記のように,NaNを含むような行列の要素の総和を求めたい

>> v = [1,nan,1]

v =

     1   NaN     1

何も考えずにsumすると

>> sum(v)

ans =

   NaN

となってしまうのを回避して,2と出力されるようにしたい.

#解決策

オプションに'omitnan'を指定する

>> sum(v, 'omitnan')

ans =

     2

おわり

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?