I have issues using datenum function because of a different date format on excel, how can I modify my dates in matlab and then run the function?n

2 visualizaciones (últimos 30 días)
EX is the data table (16888x3) and the date time format in the first column of the table is "HH:MM:SS, dd mm yyyy"
X=EX.DateTime
Unable to resolve the name 'EX.DateTime'.
Y1=EX.PM25
Y2=EX.Humidity
DT= datenum(X,"HH:MM:SS, dd mm yyyy")
  3 comentarios
Tanishq
Tanishq el 30 de Ag. de 2022
Thanks Mr. chunru for replying so fast but Actually to share the data I have to take permission from someone but I'll be right back.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 30 de Ag. de 2022
Don't use serial date numbers and datenum. Use datetime instead.
s = "12:34:56, 30 08 2022"
s = "12:34:56, 30 08 2022"
fmt = "HH:mm:SS, dd MM yyyy";
dt = datetime(s, InputFormat=fmt) % Use the default Format
dt = datetime
30-Aug-2022 12:34:00
dt2 = dt; dt2.Format = fmt % or you can use the original format
dt2 = datetime
12:34:56, 30 08 2022

Más respuestas (1)

dpb
dpb el 30 de Ag. de 2022
Don't use datenum, use datetime instead and readtable,
You can either use an import options object from detectImportOptions in which you set the format for the date format or let it read it as cellstr or string and convert.
Presuming you've done the latter to get the posted code -- it would have been more helpful to have seen that as well as the short example section of the actual input file...
EX.DateTime=datetime(EX.DateTime,'InputFormat','HH:mm:ss, yyyy-MM-dd');
EX.Time=EX.DateTime-EX.DateTime(1); % convert to duration for use in analysis
You may also find it convenient to use seconds(EX.Time) as the analysis time variable for timeseries analyses instead of the duration class, depending upon just what functions you're planning on using; not all of the Signal Processing TB has been made datetime/duration aware.

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