I need to efficiently skip lines in text file
Show older comments
I'm reading in a formatted text data file and pulling data from it. Every so often there is a break in the data and its 4 lines long. I'm reading the lines with "fgetl" and right now to skip those lines I just use
for i = 1:4
line = fgetl(fileID);
end
This seems terribly inefficient and brute force. Is there a better way?
--Clarification The skipped lines have information in them, just information I don't use. I'm also trying to avoid saving any information temporarily for the skipped lines.
1 Comment
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 7 Aug 2015
Edited: Azzi Abdelmalek
on 7 Aug 2015
You can use textscan
fid=fopen('fic.txt');
str=textscan(fid,'%s','HeaderLines',5,'delimiter','\r\n');
fclose(fid)
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!