Import series of CSV files and perform data crunching

1 次查看(过去 30 天)
I have csv data files sequentially and individually labelled as v0,v10,v20,v30,v40......v10000 in a folder. So in all its 1002 .csv files. I want to import all the data from these files each of which has 2730 rows (numerical data) X 6 colmns. Additionally with the import, I'd like to perform an even average over say every 50 sequential files to store it in a variable X which will have a size of 54600 R x 120 C (i.e 20 x 2730 R and 20 x 6) (Guess I'm correct here).
Request your assistance to perform this.
I faced some issues running a for loop with csvread and xlsread. It might be bcecause my first 6 lines in every file has header and whitespaces in it just before the data commences?
Thanks.

采纳的回答

Mohammad Sami
Mohammad Sami 2020-9-18
编辑:Mohammad Sami 2020-9-18
You need to set the NumHeader Lines to ignore the first 6 lines.
folderwcsv = 'somepath';
csvs = dir(fullfile(folderwcsv,'*.csv')); % assumes the csv are not in subfolders
data = cell(length(csvs),1);
for i = 1:length(csvs)
data{i,1} = readtable(fullfile(csvs(i).folder,csvs(i).name),'NumHeaderLines',6);
end
If the readtable doesnot work for you be default, it allows you to set all the options.
Two ways to set the options are to use either detectImportOptions or manually specificy them like follows
% if your text files are delimited
opts = delimitedTextImportOptions('NumVariables',6,'DataLines',7,'Delimiter',',');
%% for %%
data{i,1} = readtable(fullfile(csvs(i).folder,csvs(i).name),opts);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by