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.