Filter löschen
Filter löschen

Numerical difference between Matlab result and MS Excel result

2 Ansichten (letzte 30 Tage)
Zhi Hao
Zhi Hao am 27 Jun. 2011
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

Antworten (1)

Doug Eastman
Doug Eastman am 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 Kommentar
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by