MATLAB: Sum of two numbers is not accepted

delete valuesfloating pointmatrixsum

Hi everyone,
I have a problem with deleting numbers in a matrix. Let's have a matrix M, where I want to delete all rows with a specified value in the second column, e.g:
M(M(:,2)==0.141,:)=[];
All rows with 0.141 in the second column are now deleted.
Also, I tried to specify this value by a sum of two numbers:
a=0.14+0.001;
M(M(:,2)==a,:)=[];
This sum hasn't been accepted and all values are still in the matrix.
Can anyone explain me this mysterious thing please?

Best Answer

Read about comparing two floating-point numbers.
a=0.14+0.001;
tol = 10^-5 ;
idx = abs(M(:,2)-a)<=tol ;
M(idx,:)=[];