转
isnan函数matlab
isnan函数:判断数组的元素是否是NaN。(Not a Number)
matlab中出现NaN的情况:
任何关于NaN的运算,
加减法:(+inf)+(-inf)
乘法:0*inf
除法:0/0;inf/inf
Remainder(余数):rem(x,y),其中y为0或x为inf
- >> inf + (-inf)
- ans =
- NaN
- >> 0*inf
- ans =
- NaN
- >> 0/0
- ans =
- NaN
- >> inf/inf
- ans =
- NaN
- >> rem(2, 0)
- ans =
- NaN
- >> rem(inf, 2)
- ans =
- NaN
- >> rem(2, 1)
- ans =
- 0
- >> rem(3,2)
- ans =
- 1
- >> rem(6,4)
- ans =
- 2
- >> rem(4, 6)
- ans =
- 4
- >> rem(4, -2)
- ans =
- 0
isnan函数用法:
tf=isnan(A):返回一个与A相同维数的数组,若A的元素为NaN(非数值),在对应位置上返回逻辑1(真),否则返回逻辑0(假)。
- >> A = [-2, 1, 0, 3, -5]
- A =
- -2 1 0 3 -5
- >> B = 1./A
- B =
- -0.5000 1.0000 Inf 0.3333 -0.2000
- >> C = isnan(B)
- C =
- 0 0 0 0 0
- >> B1 = 0./A
- B1 =
- 0 0 NaN 0 0
- >> C1 = isnan(B1)
- C1 =
- 0 0 1 0 0