필터 지우기
필터 지우기

xlsread problem regarding reading values

조회 수: 8 (최근 30일)
Atharva Bhomle
Atharva Bhomle 2023년 6월 5일
답변: Divyanshu 2023년 6월 13일
While i read a excel sheet using xlsread, it doesn't show whole value in the variable file but when i print the value i shows more decimal places than the actual value.
For eg. the actual number in excel sheet is 3.53719759
the value shown in variable when i open it 3.5372
the value shown when i print it is 3.53719758987427
How can i get the exact same value as it is in the excel sheet?
  댓글 수: 7
Stephen23
Stephen23 2023년 6월 5일
"and it would not astonish me if routinely only 16 decimal digits were stored into the .xlsx file"
Apparently XLSX uses up to 17 digits for storing double values:
Walter Roberson
Walter Roberson 2023년 6월 5일
By the way, https://stackoverflow.com/questions/68784030/how-do-we-need-17-significant-decimal-digits-to-identify-an-arbitrary-double-pre gives an example of a number that requires 17 digits, 50388143.0682372152805328369140625
I just tested with writematrix() and confirmed that MATLAB for one writes out enough digits to be able to exactly replicate the number: writetable() writes out 50388143.068237215
Unfortunately at the moment I do not have genuine Excel handy to test what Excel does.

댓글을 달려면 로그인하십시오.

채택된 답변

Divyanshu
Divyanshu 2023년 6월 13일
The values are getting rounded off because by default MATLAB uses ‘short’ format and hence displays numbers only up to 4 decimal places.
In order to get the correct values, follow these steps:
  • Firstly, set the format to ‘long’, you can do these by executing command format long.
  • And then read the value from excel file using readtable function.
Please refer the following documentation for further details:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by