convert excel time to time in a matlab

21 次查看(过去 30 天)
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.

采纳的回答

Campion Loong
Campion Loong 2022-11-18
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by