MATLAB: Equality operator between matrix and scalar

relational operators

consider:
a=[-1:0.1:1];
c=a==.1;
it returns c as a matrix of nulls; while I expect c(12) to be 1.

Best Answer

This is due to floating point precision errors, explained here: http://blogs.mathworks.com/loren/2006/08/23/a-glimpse-into-floating-point-accuracy/
A better way to do this is by comparing against a tolerance, such as:
c = abs(a-0.1)<=eps