Convert double to datetime when importing .csv
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kim-André
el 15 de Feb. de 2024
Comentada: Kim-André
el 15 de Feb. de 2024
Hello,
I have a .csv Log with date times stored as double value, similar to:
T =
1×4 table
X1 Y1 X2 Y2
________________ __ ________________ __
45335.7751723264 1 45335.7751723264 2
When using the import function and generating a template script I´ll subsequently get "double" VariableTypes.
The format for the datetime is dd/MM/uuuu HH:mm:ss.SSS
I´ve tried using setvaropts, mainly
% Specify InputFormat according to the datetime format
opts = setvaropts(opts, ["X1", "X2"], "InputFormat", "dd/MM/uuuu HH:mm:ss.SSS");
% Specify InputFormat as double
opts = setvaropts(opts, ["X1", "X2"], "InputFormat", "double", "DateTimeFormat", "dd/MM/uuuu HH:mm:ss.SSS");
% set VariableTypes to datetime and InputFormat in setvaropts
opts = setvartype(opts, ["X1", "X2"], "datetime");
opts = setvaropts(opts,["X1", "X2"], "DatetimeFormat", "dd/MM/uuuu HH:mm:ss.SSS", "DatetimeLocale", "de_DE");
and some other variations. But I get a warning that variables can´t be convertet to datetime.
I am currently using a function that iterates over the table to convert the values but it´s taking considerable time.
Is there a possibility to set the import options to convert the double values to the correct datetime format?
Thanks for your help!
3 comentarios
Respuesta aceptada
Stephen23
el 15 de Feb. de 2024
T = readtable('Trace.csv', 'Delimiter',';', 'VariableNamingRule','preserve')
P = wildcardPattern + "(X)";
F = @(n) datetime(n, 'ConvertFrom','excel');
T = convertvars(T,P,F)
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables 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!