How to check if an object is NaN

12 Ansichten (letzte 30 Tage)
Bruno Luong
Bruno Luong am 24 Aug. 2023
Kommentiert: Dyuman Joshi am 24 Aug. 2023
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?

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by