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일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

제품

질문:

2023년 8월 24일

댓글:

2023년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by