文档帮助中心
NaN
本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。
确定哪些数组元素为 NaN
TF = isnan(A)
示例
TF = isnan(A) 返回一个逻辑数组,其中的 1 (true) 对应 A 中的 NaN 元素,0 (false) 对应其他元素。如果 A 包含复数,则 isnan(A) 中的 1 对应实部或虚部为 NaN 值的元素,0 对应实部和虚部均非 NaN 值的元素。
TF
A
1
true
0
false
isnan(A)
全部折叠
创建行向量,并确定哪些元素为 NaN。
A = 0./[-2 -1 0 1 2]
A = 1×5 0 0 NaN 0 0
TF = 1x5 logical array 0 0 1 0 0
创建一个复数数组。确定这些复数中是否包含 NaN。
A = [2 + 1i, 1/0 + 3i, 1/2 - 1i*NaN]
A = 1×3 complex 2.0000 + 1.0000i Inf + 3.0000i NaN + NaNi
TF = 1x3 logical array 0 0 1
创建数组并找到具有 NaN 值的元素。
A = [1,3,5,7,NaN,10,NaN,4,6,8]
A = 1×10 1 3 5 7 NaN 10 NaN 4 6 8
TF = 1x10 logical array 0 0 0 0 1 0 1 0 0 0
使用 TF 对 A 进行索引,以访问 A 中的 NaN 元素。将 NaN 值替换为 0。
A(TF) = 0
A = 1×10 1 3 5 7 0 10 0 4 6 8
输入数组,指定为标量、向量、矩阵或多维数组。
如果 x 是实数标量,则 isfinite(x)、isinf(x) 和 isnan(x) 中只有一个返回逻辑值 1 (true)。
x
isfinite(x)
isinf(x)
isnan(x)
对于复数标量 z,isinf(z) 和 isnan(z) 都可以返回逻辑值 1。例如,isinf(complex(Inf,NaN)) 和 isnan(complex(Inf,NaN)) 都返回逻辑值 1。
z
isinf(z)
isnan(z)
isinf(complex(Inf,NaN))
isnan(complex(Inf,NaN))
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
此函数完全支持 GPU 数组。有关详细信息,请参阅Run MATLAB Functions on a GPU (Parallel Computing Toolbox)。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
is* | isfinite | isinf | ismissing | NaN
is*
isfinite
isinf
ismissing
您的系统上存在此示例的修改版本。是否要打开此版本?
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office