Import multiple .txt files
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I have some text files that I want to import all at once. I am using the following code to try to import them.
files = dir(fullfile(roothpath, '*.txt'));
file_paths = fullfile({files.folder}, {files.name});
for i = 1 : numel(file_paths)
data = textread(file_paths{i}, '');
end
However, the text files have headers and I am having trouble removing them. So my question is what can I do to import them with commands to remove the header and import all the files.
Thanks.
0 个评论
回答(1 个)
Chunru
2021-7-29
Use "headerlines" parameter to ignore the header lines:
data = textread(file_paths{i}, format, 'headerlines', headlineNum);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!