In matlab, Sometimes when you try to compare two numbers, they don't usually gives you the answer you excepted. When you compare two integers,
will gives you 1.
but when you compare double, sometimes it doesn't work. Simple cases that if you do
will give you 1 still. But if you save a into a file, and use
textread(filename) to get the value, the value may still look like 0.001, but if you do
It might give you 0 because the a was read from a file and it was in some weird format. This might be a bug. Some people fix it by doing
it basically means if a and 0.001 is very close, then they are equal.
I personally have a quicker fix.
For some reason, after any operation on the variable, the value no long have anything weird going on inside.