Clear Filters
Clear Filters

why is NaN not of 'NaN type' in Simulink?

3 views (last 30 days)
Hi everyone,
Please, could anyone explain why the constant block NaN is not of type NaN?
Thank you in advance!
Best regards,
  1 Comment
Nicolas CRETIN
Nicolas CRETIN on 2 May 2024
To solve the problem I first converted my input into a string and then I applied a string comparison:
But this is still a weird behaviour

Sign in to comment.

Accepted Answer

Paul on 2 May 2024
It looks like the block labeled "assertion1" is a Compare To Constant block.
Instead use a Relational Operator block, which supports isNaN functionality.

More Answers (1)

Steven Lord
Steven Lord on 2 May 2024
By the definition of NaN, NaN is not equal to anything (including itself.) This is documented on the documentation pages for the NaN function as well as the documentation page for the == operator.
If you can call MATLAB functions in your model, use isequaln to perform equality testing including treating NaN as equal to NaN.
x = NaN;
x == x % false
ans = logical
isequal(x, x) % false
ans = logical
isequaln(x, x) % true
ans = logical




Community Treasure Hunt

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

Start Hunting!