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 Related SolutionsMATLAB: If within while loop not recognized A trivial answer:Use ismembertol for comparing values with tolerance tol=1e-6; if ismembertol(t,0.05,tol) MATLAB: Help regarding “format long” Welcome to the joy of round-off error. 0.0002 is not exactly representable in binary, hence adding these floating point numbers causes error at the level of machine precision. Enter eps(4) to see what machine precision is for these values. Related QuestionImprecise Basic operations0.9-0.89 is 0.010000000000000000208166817117217Rounding using ‘fix’… possibly a bugComputer ArithematicWeird result, why I can’t find -0.809 and 0.309 in -1:0.001:1??About the calculation preciseTwo equal numbers are not equal
Best Answer