MATLAB Answers

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

10 views (last 30 days)
Bertilla Raque
Bertilla Raque on 12 Dec 2019
Answered: Cris LaPierre on 18 Mar 2020
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?

  0 Comments

Sign in to comment.

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).

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2012b

Translated by