Convert double to datetime when importing .csv
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Stephen23
2024 年 2 月 15 日
T = readtable('Trace.csv', 'Delimiter',';', 'VariableNamingRule','preserve')
P = wildcardPattern + "(X)";
F = @(n) datetime(n, 'ConvertFrom','excel');
T = convertvars(T,P,F)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!