read multiple csv files and extract first 10 rows only
13 次查看(过去 30 天)
显示 更早的评论
I have multiple (more than 100) csv files. I want a loop to read the csv files and extract only first ten rows from each csv files.
Thanks!
0 个评论
采纳的回答
dpb
2019-5-13
Just read each file in turn and save the first N lines...
NLines=10; % how many wanted to save...make variable so can change at will...
d=dir('Appropriate*WildCardPattern*.csv');
for i=1:numel(d)
data=csvread(d(i).name);
data=data(1:NLines,:);
...
% do whatever with this file's data here...
end
2 个评论
dpb
2019-5-13
You said were .csv files...those are Excel files--use an appropriate way to read Excell file.
更多回答(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!