Why does my time data from Excel get read into MATLAB as a double?
4 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2022 年 2 月 1 日
回答済み: MathWorks Support Team
2022 年 2 月 24 日
In Excel I have a column of custom time data, e.g., 12:27:43 AM. When I read the data with "readtable", MATLAB imports it as a double, e.g., 0.0192. Why is this happening and how can I import my Excel time data into MATLAB using the datetime type?
採用された回答
MathWorks Support Team
2022 年 2 月 1 日
What's Happening
If the Excel format is "custom", MATLAB is unable to tell that it resembles a datetime datatype and does not read it as such. Instead, MATLAB reads the data exactly as Excel stores it. In this case as Excel's default format for time information, a decimal number. So while Excel may display 12:27:43 AM, it stores the time as 0.0192 and that is what's passed to MATLAB.
Resolving the Issue
To resolve this, you can use the "datetime" function and specify that MATLAB needs to convert the time from Excel's default time format:
newTime = datetime(decimalTime, "ConvertFrom", "excel")
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!