Import data csv with date/time and other info with setvaropts
45 ビュー (過去 30 日間)
古いコメントを表示
I try to import a csv file into a table int the workspace.
My fist colonn in the csv is date with a time following : day/ month/ year hour minute.
The other collonns are datas that could be considered as double.
The code I am using is :
opts = detectImportOptions('essai_data_3.csv','Delimiter',';')
opts.VariableTypes = {'datetime','double','double','double','double'};
opts = setvaropts(opts,1,'DatetimeFormat','dd.MM.uuuu HH:mm:ss');
opts = setvaropts(opts,2:5,'DecimalSeparator',',');
T = readtable('essai_data_3.csv',opts);
T.Properties.VariableNames{1} = 'Time';
T.Properties.VariableNames{2} = 'Data1';
T.Properties.VariableNames{3} = 'Data2';
I tried to read the datasheet of "setvaropts" and use the answears from other questions but i didn't reached what I wanted and I get an error warning as my date format is not recognised because of an "'anbiguity" (PLEASE look at the orange warning)
0 件のコメント
採用された回答
Simon Chan
2022 年 9 月 10 日
Try this:
opts = detectImportOptions('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121365/essai_data_3.csv','Delimiter',';');
opts.VariableTypes = {'datetime','double','double','double','double'};
opts = setvaropts(opts,1,'InputFormat','dd/MM/uuuu HH:mm');
opts = setvaropts(opts,2:5,'DecimalSeparator',',');
T = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121365/essai_data_3.csv',opts)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!