MATLAB: Import CSV data into Matlab

csvdata importMATLABmatlab functionstruct

Could you attach some sample data?
Also, which MATLAB version are you using? There have been recent changes in the handling of duration data.
Could you confirm that you need those first two lines read in and stored as part of the table? You tell it not to read the variable names, and you also do not use HeaderLines, so the implication is that you need those two lines stored.

Best Answer

opt = detectImportOptions('EE_moderate.csv');
opt = setvartype(opt, [2 5], 'datetime');
opt = setvaropts(opt, [2 5], 'InputFormat', 'dd-MMM yyyy', 'DatetimeFormat', 'eee uuuu-MM-dd HH:mm:ss' );
...
T = readtable(fullfile(filedir,files1(i).name), opt);
T.date = T.date + T.time;
T.date_1 = T.date_1 + T.time_1;
patient_1(i).Data = T(:,[2 5 7:end]);
...