convert excel time to time in a matlab

19 visualizaciones (últimos 30 días)
Lucas
Lucas el 15 de Nov. de 2022
Respondida: Campion Loong el 18 de Nov. de 2022
In excel file (.csv) column A is in format of (12:37:48.123 AM) and I want to have it in MatLab as 12:37:48.123
I tried using the following code:
UTCtime = datetime(dat(8:lastindex), 'Format', 'hh:mm:ss:SSS a')
But got this error:
Error using datetime (line 597)
Numeric input data must be a matrix with three or six columns, or else three, six, or seven separate numeric arrays. You can also create datetimes
from a single numeric array using the 'ConvertFrom' parameter.
Error in Event_129_BATS02 (line 91)
UTCtime = datetime(dat(8:lastindex), 'Format', 'hh:mm:ss:SSS a')
Please help.

Respuesta aceptada

Campion Loong
Campion Loong el 18 de Nov. de 2022
Simply use 'InputFormat' to parse the excel timestamp, and 'Format' to display it in your format of choice
% Made up data - you can parse an array in one call
excel_timestamp = ["12:37:48.123 AM"; "1:34:42.153 AM"; "3:25:31.635 AM"];
% Use the "InputFormat" & "Format" Name/Value pairs right at construction
datetime(excel_timestamp,"InputFormat","hh:mm:ss.SSS a", "Format", "hh:mm:ss.SSS")
ans = 3×1 datetime array
12:37:48.123 01:34:42.153 03:25:31.635

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by