Why does my time data from Excel get read into MATLAB as a double?

5 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 1 Fév 2022
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")

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by