Numerical difference between Matlab result and MS Excel result
5 views (last 30 days)
Show older comments
Hi,
I am interested in obtaining exact output between matlab calculation and MS excel computation.
Here's an example. In excel, key in this: 123456789123456789
Result in MS excel: 123456789123456000
In matlab, key in this: 123456789123456789
Result in Matlab: 123456789123457000
Can anyone advise me how can I eliminate the difference between the two platforms?
zhi hao
0 Comments
Answers (1)
Doug Eastman
on 27 Jun 2011
When I type '123456789123456789' in a numeric field in Excel, I get 123456789123456000. The issue is due to floating point data types, discussed extensively (for example see Cleve's Corner. If you type
eps(123456789123456789)
You can see the accuracy around that number for a double data type is 16, so in MATLAB the value represented is 123456789123456780.
The only way I see to use the full number is Excel is to format the cell as text.
In MATLAB there are a couple of options, you could use VPA in the Symbolic Math Toolbox, or you could use the 64-bit integer data type, try:
uint64(123456789123456789)
1 Comment
Walter Roberson
on 27 Jun 2011
Note: until quite recent releases, uint64(123456789123456789) would construct the double precision number corresponding to 123456789123456789 and then would convert that number to uint64. There was no direct way in those releases to get a uint64 number that needed more than 53 bits.
See Also
Categories
Find more on Data Import from MATLAB 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!