How can I skip lines when loading a text file?
71 次查看(过去 30 天)
显示 更早的评论
Is there a way to use load to load a text file but skip a few lines which contain headers and other info and just load numerical data in columns that come after the headers?
0 个评论
回答(1 个)
Sven
2012-2-1
Hi Baba, try importdata:
importdata(FILENAME, DELIM, NHEADERLINES) loads data from ASCII file FILENAME, reading numeric data starting from line NHEADERLINES+1.
5 个评论
Shania Hurst
2016-11-7
编辑:Shania Hurst
2016-11-7
Using importdata with nheaderlines specified works for almost every file for me, but for some reason, I have one file that instead of skipping the first 20 lines as I want, instead imports ONLY the first 20 lines. I have no idea what would cause this to happen, does any one know of any circumstance in which this would happen? The file is a .txt file and has nearly 85k lines of data. The command I used is d = importdata('data.txt',' ',20);
Walter Roberson
2016-11-7
Shania Hurst, I suggest you consider using readtable() with HeaderLines . (readtable() might even be able to figure out for itself how many header lines are there.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!