Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何测试给定值是infinity,-infinity或NaN. isinf仅适用于“双”,并且无法测试NaN值。
infinity
-infinity
NaN.
isinf
NaN
试试isfinite。例如:
isfinite
isfinite([0 1 2 inf -inf nan]) ans = 1 1 1 0 0 0
您可以使用isinf(x) | isnan(x).
isinf(x) | isnan(x)
是|一个元素逻辑或。因此,如果元素为 ±或,则上述命令对于每个元素都转换为 true ,否则转换为 falsexInfNaN。
|
x
Inf