Convert double to datetime when importing .csv

5 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 15 Feb 2024
Please upload a sample data file by clicking the paperclip button.
Kim-André
Kim-André on 15 Feb 2024
Sample File Attached.
*_X[...]1 columns contain datetime.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 15 Feb 2024
T = readtable('Trace.csv', 'Delimiter',';', 'VariableNamingRule','preserve')
T = 9×42 table
B1_CellT_1(X) B1_CellT_1(Y) B1_CellT_4(X) B1_CellT_4(Y) B1_CellT_5(X) B1_CellT_5(Y) B1_CellV_1(X) B1_CellV_1(Y) B1_CellV_10(X) B1_CellV_10(Y) B1_CellV_11(X) B1_CellV_11(Y) B1_CellV_12(X) B1_CellV_12(Y) B1_CellV_13(X) B1_CellV_13(Y) B1_CellV_14(X) B1_CellV_14(Y) B1_CellV_2(X) B1_CellV_2(Y) B1_CellV_3(X) B1_CellV_3(Y) B1_CellV_4(X) B1_CellV_4(Y) B1_CellV_5(X) B1_CellV_5(Y) B1_CellV_6(X) B1_CellV_6(Y) B1_CellV_7(X) B1_CellV_7(Y) B1_CellV_8(X) B1_CellV_8(Y) B1_CellV_9(X) B1_CellV_9(Y) B1_CellV_Max(X) B1_CellV_Max(Y) B1_CellV_Min(X) B1_CellV_Min(Y) B1_Current(X) B1_Current(Y) B1_Voltage(X) B1_Voltage(Y) _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _______________ _______________ _______________ _______________ _____________ _____________ _____________ _____________ 45336 1 45336 1 45336 1 45336 3423.4 45336 3418.8 45336 3416.7 45336 3419.8 45336 3421.3 45336 3414.4 45336 3425.2 45336 3414.6 45336 3417.5 45336 3418.2 45336 3421.5 45336 3414.8 45336 3421.8 45336 3419.8 45336 3425.2 45336 3414.4 45336 -0.01959 45336 47.9 45336 0 45336 1 45336 1 45336 3423.3 45336 3419 45336 3416.5 45336 3419.6 45336 3421.3 45336 3414.5 45336 3425.3 45336 3414.5 45336 3417.3 45336 3418.2 45336 3421.6 45336 3414.8 45336 3421.7 45336 3419.8 45336 3425.3 45336 3414.3 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.3 45336 3418.8 45336 3416.6 45336 3419.7 45336 3421.2 45336 3414.3 45336 3425.3 45336 3414.7 45336 3417.2 45336 3418.1 45336 3421.5 45336 3414.9 45336 3421.8 45336 3419.7 45336 3425.2 45336 3414.4 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.4 45336 3418.9 45336 3416.6 45336 3419.6 45336 3421.2 45336 3414.2 45336 3425.3 45336 3414.6 45336 3417.4 45336 3417.9 45336 3421.5 45336 3414.8 45336 3421.8 45336 3419.7 45336 3425.2 45336 3414.4 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.3 45336 3418.9 45336 3416.6 45336 3419.7 45336 3421.1 45336 3414.4 45336 3425.2 45336 3414.6 45336 3417.3 45336 3418.1 45336 3421.5 45336 3414.8 45336 3421.7 45336 3419.7 45336 3425.3 45336 3414.3 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.3 45336 3418.9 45336 3416.7 45336 3419.7 45336 3421.4 45336 3414.3 45336 3425.2 45336 3414.7 45336 3417.4 45336 3418.2 45336 3421.5 45336 3414.7 45336 3421.8 45336 3419.7 45336 3425.2 45336 3414.3 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.3 45336 3418.8 45336 3416.7 45336 3419.7 45336 3421.3 45336 3414.4 45336 3425.2 45336 3414.7 45336 3417.3 45336 3418.2 45336 3421.5 45336 3414.8 45336 3421.6 45336 3419.6 45336 3425.3 45336 3414.4 45336 -0.01959 45336 47.9 45336 1 45336 1 45336 1 45336 3423.3 45336 3418.9 45336 3416.6 45336 3419.9 45336 3421.3 45336 3414.4 45336 3425.4 45336 3414.6 45336 3417.2 45336 3418 45336 3421.5 45336 3414.7 45336 3421.7 45336 3419.7 45336 3425.3 45336 3414.2 45336 -0.01959 45336 47.9 45336 0 45336 1 45336 1 45336 3423.2 45336 3418.9 45336 3416.5 45336 3419.6 45336 3421.4 45336 3414.3 45336 3425.3 45336 3414.7 45336 3417.3 45336 3418.1 45336 3421.5 45336 3414.7 45336 3421.8 45336 3419.8 45336 3425.2 45336 3414.3 45336 -0.01959 45336 47.9
P = wildcardPattern + "(X)";
F = @(n) datetime(n, 'ConvertFrom','excel');
T = convertvars(T,P,F)
T = 9×42 table
B1_CellT_1(X) B1_CellT_1(Y) B1_CellT_4(X) B1_CellT_4(Y) B1_CellT_5(X) B1_CellT_5(Y) B1_CellV_1(X) B1_CellV_1(Y) B1_CellV_10(X) B1_CellV_10(Y) B1_CellV_11(X) B1_CellV_11(Y) B1_CellV_12(X) B1_CellV_12(Y) B1_CellV_13(X) B1_CellV_13(Y) B1_CellV_14(X) B1_CellV_14(Y) B1_CellV_2(X) B1_CellV_2(Y) B1_CellV_3(X) B1_CellV_3(Y) B1_CellV_4(X) B1_CellV_4(Y) B1_CellV_5(X) B1_CellV_5(Y) B1_CellV_6(X) B1_CellV_6(Y) B1_CellV_7(X) B1_CellV_7(Y) B1_CellV_8(X) B1_CellV_8(Y) B1_CellV_9(X) B1_CellV_9(Y) B1_CellV_Max(X) B1_CellV_Max(Y) B1_CellV_Min(X) B1_CellV_Min(Y) B1_Current(X) B1_Current(Y) B1_Voltage(X) B1_Voltage(Y) ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ ______________ ____________________ ______________ ____________________ ______________ ____________________ ______________ ____________________ ______________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _____________ ____________________ _______________ ____________________ _______________ ____________________ _____________ ____________________ _____________ 13-Feb-2024 18:36:14 1 13-Feb-2024 18:36:14 1 13-Feb-2024 18:36:14 1 13-Feb-2024 18:36:12 3423.4 13-Feb-2024 18:36:12 3418.8 13-Feb-2024 18:36:12 3416.7 13-Feb-2024 18:36:12 3419.8 13-Feb-2024 18:36:12 3421.3 13-Feb-2024 18:36:12 3414.4 13-Feb-2024 18:36:12 3425.2 13-Feb-2024 18:36:12 3414.6 13-Feb-2024 18:36:12 3417.5 13-Feb-2024 18:36:12 3418.2 13-Feb-2024 18:36:12 3421.5 13-Feb-2024 18:36:12 3414.8 13-Feb-2024 18:36:12 3421.8 13-Feb-2024 18:36:12 3419.8 13-Feb-2024 18:36:12 3425.2 13-Feb-2024 18:36:12 3414.4 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:36:44 0 13-Feb-2024 18:36:44 1 13-Feb-2024 18:36:44 1 13-Feb-2024 18:36:13 3423.3 13-Feb-2024 18:36:13 3419 13-Feb-2024 18:36:13 3416.5 13-Feb-2024 18:36:13 3419.6 13-Feb-2024 18:36:13 3421.3 13-Feb-2024 18:36:13 3414.5 13-Feb-2024 18:36:13 3425.3 13-Feb-2024 18:36:13 3414.5 13-Feb-2024 18:36:13 3417.3 13-Feb-2024 18:36:13 3418.2 13-Feb-2024 18:36:13 3421.6 13-Feb-2024 18:36:13 3414.8 13-Feb-2024 18:36:13 3421.7 13-Feb-2024 18:36:13 3419.8 13-Feb-2024 18:36:14 3425.3 13-Feb-2024 18:36:14 3414.3 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:37:14 1 13-Feb-2024 18:37:14 1 13-Feb-2024 18:37:14 1 13-Feb-2024 18:36:14 3423.3 13-Feb-2024 18:36:14 3418.8 13-Feb-2024 18:36:14 3416.6 13-Feb-2024 18:36:14 3419.7 13-Feb-2024 18:36:14 3421.2 13-Feb-2024 18:36:14 3414.3 13-Feb-2024 18:36:14 3425.3 13-Feb-2024 18:36:14 3414.7 13-Feb-2024 18:36:14 3417.2 13-Feb-2024 18:36:14 3418.1 13-Feb-2024 18:36:14 3421.5 13-Feb-2024 18:36:14 3414.9 13-Feb-2024 18:36:14 3421.8 13-Feb-2024 18:36:14 3419.7 13-Feb-2024 18:36:16 3425.2 13-Feb-2024 18:36:16 3414.4 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:37:44 1 13-Feb-2024 18:37:44 1 13-Feb-2024 18:37:44 1 13-Feb-2024 18:36:15 3423.4 13-Feb-2024 18:36:15 3418.9 13-Feb-2024 18:36:15 3416.6 13-Feb-2024 18:36:15 3419.6 13-Feb-2024 18:36:15 3421.2 13-Feb-2024 18:36:15 3414.2 13-Feb-2024 18:36:15 3425.3 13-Feb-2024 18:36:15 3414.6 13-Feb-2024 18:36:15 3417.4 13-Feb-2024 18:36:15 3417.9 13-Feb-2024 18:36:15 3421.5 13-Feb-2024 18:36:15 3414.8 13-Feb-2024 18:36:15 3421.8 13-Feb-2024 18:36:15 3419.7 13-Feb-2024 18:36:18 3425.2 13-Feb-2024 18:36:18 3414.4 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:38:14 1 13-Feb-2024 18:38:14 1 13-Feb-2024 18:38:14 1 13-Feb-2024 18:36:16 3423.3 13-Feb-2024 18:36:16 3418.9 13-Feb-2024 18:36:16 3416.6 13-Feb-2024 18:36:16 3419.7 13-Feb-2024 18:36:16 3421.1 13-Feb-2024 18:36:16 3414.4 13-Feb-2024 18:36:16 3425.2 13-Feb-2024 18:36:16 3414.6 13-Feb-2024 18:36:16 3417.3 13-Feb-2024 18:36:16 3418.1 13-Feb-2024 18:36:16 3421.5 13-Feb-2024 18:36:16 3414.8 13-Feb-2024 18:36:16 3421.7 13-Feb-2024 18:36:16 3419.7 13-Feb-2024 18:36:20 3425.3 13-Feb-2024 18:36:20 3414.3 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:38:44 1 13-Feb-2024 18:38:44 1 13-Feb-2024 18:38:44 1 13-Feb-2024 18:36:17 3423.3 13-Feb-2024 18:36:17 3418.9 13-Feb-2024 18:36:17 3416.7 13-Feb-2024 18:36:17 3419.7 13-Feb-2024 18:36:17 3421.4 13-Feb-2024 18:36:17 3414.3 13-Feb-2024 18:36:17 3425.2 13-Feb-2024 18:36:17 3414.7 13-Feb-2024 18:36:17 3417.4 13-Feb-2024 18:36:17 3418.2 13-Feb-2024 18:36:17 3421.5 13-Feb-2024 18:36:17 3414.7 13-Feb-2024 18:36:17 3421.8 13-Feb-2024 18:36:17 3419.7 13-Feb-2024 18:36:22 3425.2 13-Feb-2024 18:36:22 3414.3 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:39:14 1 13-Feb-2024 18:39:14 1 13-Feb-2024 18:39:14 1 13-Feb-2024 18:36:18 3423.3 13-Feb-2024 18:36:18 3418.8 13-Feb-2024 18:36:18 3416.7 13-Feb-2024 18:36:18 3419.7 13-Feb-2024 18:36:18 3421.3 13-Feb-2024 18:36:18 3414.4 13-Feb-2024 18:36:18 3425.2 13-Feb-2024 18:36:18 3414.7 13-Feb-2024 18:36:18 3417.3 13-Feb-2024 18:36:18 3418.2 13-Feb-2024 18:36:18 3421.5 13-Feb-2024 18:36:18 3414.8 13-Feb-2024 18:36:18 3421.6 13-Feb-2024 18:36:18 3419.6 13-Feb-2024 18:36:24 3425.3 13-Feb-2024 18:36:24 3414.4 13-Feb-2024 18:36:12 -0.01959 13-Feb-2024 18:36:12 47.9 13-Feb-2024 18:39:44 1 13-Feb-2024 18:39:44 1 13-Feb-2024 18:39:44 1 13-Feb-2024 18:36:19 3423.3 13-Feb-2024 18:36:19 3418.9 13-Feb-2024 18:36:19 3416.6 13-Feb-2024 18:36:19 3419.9 13-Feb-2024 18:36:19 3421.3 13-Feb-2024 18:36:19 3414.4 13-Feb-2024 18:36:19 3425.4 13-Feb-2024 18:36:19 3414.6 13-Feb-2024 18:36:19 3417.2 13-Feb-2024 18:36:19 3418 13-Feb-2024 18:36:19 3421.5 13-Feb-2024 18:36:19 3414.7 13-Feb-2024 18:36:19 3421.7 13-Feb-2024 18:36:19 3419.7 13-Feb-2024 18:36:26 3425.3 13-Feb-2024 18:36:26 3414.2 13-Feb-2024 18:36:13 -0.01959 13-Feb-2024 18:36:13 47.9 13-Feb-2024 18:40:14 0 13-Feb-2024 18:40:14 1 13-Feb-2024 18:40:14 1 13-Feb-2024 18:36:20 3423.2 13-Feb-2024 18:36:20 3418.9 13-Feb-2024 18:36:20 3416.5 13-Feb-2024 18:36:20 3419.6 13-Feb-2024 18:36:20 3421.4 13-Feb-2024 18:36:20 3414.3 13-Feb-2024 18:36:20 3425.3 13-Feb-2024 18:36:20 3414.7 13-Feb-2024 18:36:20 3417.3 13-Feb-2024 18:36:20 3418.1 13-Feb-2024 18:36:20 3421.5 13-Feb-2024 18:36:20 3414.7 13-Feb-2024 18:36:20 3421.8 13-Feb-2024 18:36:20 3419.8 13-Feb-2024 18:36:28 3425.2 13-Feb-2024 18:36:28 3414.3 13-Feb-2024 18:36:13 -0.01959 13-Feb-2024 18:36:13 47.9

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!