Creating vectors from 0 to 1, i.e. 0:0.01:1 leads to invisible rounding errors?
Show older comments
Hi,
I came across the following problem while trying to merge two tables with innerjoin:
Whenever I create vectors counting up from 0 to 1 tiny rounding errors seem to creep in, which one can only notice when scaling the vector up i.e. looking at (0:0.01:1)'*100.
Is there a chance I might have screwed up my Matlab settings at some point?

1 Comment
Stephen23
on 3 Mar 2018
This topic comes up very often:
etc, etc, etc
Always use a tolerance when comparing floating point values.
Accepted Answer
More Answers (1)
Testdriver
on 3 Mar 2018
0 votes
2 Comments
Ahmet Cecen
on 3 Mar 2018
Edited: Ahmet Cecen
on 3 Mar 2018
Always round your numbers (to an appropriate significant digit) if you want to use them as indices or keys in a dataset, just good practice. Better yet, use int64 if at all possible.
Walter Roberson
on 3 Mar 2018
With the one exception that if the data is certain to be drawn from exactly the same source then it is fair to compare it for equality.
For example, although you should not compare a computed value to 0.01 exactly, it is fair to test x == max(x) because the max(x) will be a bitwise identical copy of some element of x.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!