MATLAB: A simple “bug” in finding an element in an array using find()

floating pointMATLABmatrix manipulationnot a bug

Hi, I am not sure if it is a bug in matlab, but when I just simply try to find an element in an array:
list=-1:0.1:1;
find(list=0.1)
I get an strange result which is Empty matrix: 1-by-0. Instead, if I try find(list=0.6), I get the correct result 17.
Anyone have any idea?

Best Answer

Welcome to floating-point approximation error, and the way the colon operator works.
Try this:
list=-1:0.1:1;
find(list<=0.1,1,'last')