How to start reading from a specific line in a text file?

6 views (last 30 days)
I have a text file that has both text and numeric data. How do I read from a particular line to a particular line, say from line 40 to 50 and assign the numeric data to variable names?

Answers (1)

Cris LaPierre
Cris LaPierre on 18 Mar 2020
What type of text file?
Genearlly, you would use fseek to get to the starting point you want, and fgetl to read in your data line by line. However, fseek requires you to specify the number of bytes to move.
You could use textscan, which allows you to specify the number of headerlines. If the format of your numeric data is the same on each line, you could also specify how many times to apply the specified format spec (number of lines to read in).

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!