フィルターのクリア

Numerical difference between Matlab result and MS Excel result

2 ビュー (過去 30 日間)
Zhi Hao
Zhi Hao 2011 年 6 月 27 日
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

回答 (1 件)

Doug Eastman
Doug Eastman 2011 年 6 月 27 日
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 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 27 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by