MATLAB: Is this if statement does not work

errorfloating pointif statementloop

if (oval1x ~= sObjVal1(1) || oval1x ~= sObjVal1(end))
cd=1;
else
cd=Inf;
end
it happened that oval1x=4.2139; and sObjVal1(1)=4.2139; but the loop did not work correctly
Edit: is there a way to correct this issue?

Best Answer

Because they are float numbers, reading the below links might help you better about floating numbers:
You could add tolerance to satisfy the conditions , search inside the forum with the tag "floating point" you would find lots of explanations about it.