Info

This question is closed. Reopen it to edit or answer.

Parsing Ugly Files

2 views (last 30 days)
Charles
Charles on 28 Jun 2011
Closed: MATLAB Answer Bot on 20 Aug 2021
Is there a faster way then fgetl or fgets to read a text file line by line? The data I need out of a text file is very specific and if I have an IF statement looking for that format then the solution is quite simple. That being said both of these functions are VERY slow and I could use some ideas on how to better do this.
  1 Comment
Jan
Jan on 28 Jun 2011
FGETS is not slow usually, if you process files on your local harddisk. Please post your code such that we could find other problems.

Answers (1)

Walter Roberson
Walter Roberson on 28 Jun 2011
There are various methods to read in files as continuous strings (e.g., fileread()) or as cell arrays of strings [that might be lines] (such as textscan() with '^[^\n]' format).
If the file is fairly big, you would not want to fileread() it, but you might want to read groups of lines (i.e., textscan); reading groups might require reading "a little more" if you detect that the target might have started but be incomplete in what you have buffered.
You might be able to use strcmp() or regexp() to find the key text that marks the beginning of a block.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!