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

5 ビュー (過去 30 日間)
Nicolas CRETIN
Nicolas CRETIN 2024 年 5 月 2 日
コメント済み: Nicolas CRETIN 2024 年 5 月 6 日
Hi everyone,
Please, could anyone explain why the constant block NaN is not of type NaN?
Thank you in advance!
Best regards,
Nicolas
  1 件のコメント
Nicolas CRETIN
Nicolas CRETIN 2024 年 5 月 2 日
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

サインインしてコメントする。

採用された回答

Paul
Paul 2024 年 5 月 2 日
It looks like the block labeled "assertion1" is a Compare To Constant block.
Instead use a Relational Operator block, which supports isNaN functionality.
  1 件のコメント
Nicolas CRETIN
Nicolas CRETIN 2024 年 5 月 6 日
Oh, right thank you!

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2024 年 5 月 2 日
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
0
isequal(x, x) % false
ans = logical
0
isequaln(x, x) % true
ans = logical
1
  1 件のコメント
Nicolas CRETIN
Nicolas CRETIN 2024 年 5 月 2 日
Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSources についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by