loop to read files
조회 수: 4 (최근 30일)
이전 댓글 표시
I have data_2010.csv, data_2011.csv,... in the same directory. I want to write a loop like
for i=2010:1:2020
(table data_i)= readtable(data_i.csv)
end
Please advise.
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 6월 12일
편집: Ameer Hamza
2020년 6월 12일
To read all csv files one by one
files = dir('*.csv');
table_data = cell(1, numel(files));
for i=1:numel(files)
filename = files(i).name;
table_data{i} = readtable(filename);
end
To only read these specific files
range = 2010:1:2020;
table_data = cell(1, numel(range));
for i = 1:numel(range)
filename = sprintf('data_%d.csv', range(i));
table_data{i} = readtable(filename);
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Other Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!