I need a workaround for this issue. An explanation of why this is ONLY happening to one number would also be very helpful as I'd like to avoid this in the future. I've set the format long
option to show what is happening.
I start by creating a vector. Just like this:
>> vec = [0, 2.4, 2.8, 5.2, 5.6]
It returns, as expected, this:
vec =
0 2.400000000000000 2.800000000000000 5.200000000000000 5.600000000000000
Now, I want to add 0.4 to all of these:
>> vec + 0.4
But, here is my output:
ans =
0.400000000000000 2.800000000000000 3.200000000000000 5.600000000000001 6.000000000000000
Notice the rounding error on 5.6. It shouldn't have that 1. I tried using vec + round(0.4,1)
but that also does not work.
Why does this only happen to 5.6? How can I avoid this? If it is unavoidable, how can I work around it?
EDIT: Also, in case this is useful.
MATLAB Version: 8.6.0.267246 (R2015b) Operating System: Microsoft Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1) Java Version: Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode