Because two NaNs are not equal to each other, logical operations involving NaNs always return false, except ~= (not equal). Consequently,
NaN ~= NaN
ans =
1
NaN == NaN
ans =
0
and the NaNs in a vector are treated as different unique elements.
unique([1 1 NaN NaN])
ans =
1 NaN NaN
Use the isnan function to detect NaNs in an array.
isnan([1 1 NaN NaN])
ans =
0 0 1 1