- #1
Pythagorean
Gold Member
- 4,400
- 312
so I make a vector:
V3 = [15.05:.05:15.15];
V3c = [14.75:.05:15.15];
find(V3c == Vc(2))
and I get nothing (no matches)
apparently, when MATLAB constructed V3, it did so such that:
V3(2) == 15.10000000000001
and
V3c(8) == 15.10000000000000
what's the deal?
My cheap way around this is:
V3 = fix(V3*1000)/1000
so I multiply by 1000, shave off the remaining decimals, and divide by 1000, but this doesn't seem robust to me. Is there a better way to handle this floating point difference?
V3 = [15.05:.05:15.15];
V3c = [14.75:.05:15.15];
find(V3c == Vc(2))
and I get nothing (no matches)
apparently, when MATLAB constructed V3, it did so such that:
V3(2) == 15.10000000000001
and
V3c(8) == 15.10000000000000
what's the deal?
My cheap way around this is:
V3 = fix(V3*1000)/1000
so I multiply by 1000, shave off the remaining decimals, and divide by 1000, but this doesn't seem robust to me. Is there a better way to handle this floating point difference?