Read multiple CSV file with header and datetime

Hello,
i have multiple CSV files with 2 header lines (some files missing header) and first column being datetime. I would like to import files based on filename filter. I did this by creating a datastore and using "readall" command. is there a better way to do this?
Thanks for your input!
Best regards,
R

回答 (1 件)

Chandu
Chandu 2022 年 3 月 15 日

0 投票

Hi,
Multiple CSV files can be imported into MATLAB workspace using a loop and textscan MATLAB function can be used for filtering. textscan will let you specify 'HeaderLines' to skip over the header. Refer the following script,
for i = 1: numfids
f = fopen (strcat (strDir, fnames(i).name);
X = textscan (f,'%s%f','Delimiter',',','HeaderLines',1);
fclose(f);
end
X would be a cell array of parsed columns (note this code reads the timestamp as a string). Refer textscan MathWorks Documentation for more help.

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

RA
2021 年 1 月 19 日

回答済み:

2022 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by