How to check if an object is NaN

12 visualizaciones (últimos 30 días)
Bruno Luong
Bruno Luong el 24 de Ag. de 2023
Comentada: Dyuman Joshi el 24 de Ag. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by