How to check if an object is NaN

12 次查看(过去 30 天)
I want to check a generic object "is equal" to NaN.
The command isnan(object) throws an error and the command isequal(object, NaN) returns false if object is NaN.
So my attempt is this rather complicated expression
isobjecteqNaN = @(object)isa(object,'double') && isscalar(object) && isnan(object);
isobjecteqNaN(NaN)
ans = logical
1
isobjecteqNaN({NaN})
ans = logical
0
Is there any better way to check?

采纳的回答

Walter Roberson
Walter Roberson 2023-8-24
https://www.mathworks.com/help/matlab/ref/isequaln.html
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-8-24
How exactly will this work?
Suppose the input is {NaN}, how to check for this?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by