How to read specific lines from a text file and store them in a matrix?

8 views (last 30 days)
Hello everyone,
I want to create a matrix from the attached text file that only includes the lines after the one that reads "#begindata". Basically, I want a matrix that includes the headers of the columns and all the numeric data from the file, but none of the information preceding it.
Also, would it be possible to use the same code when reading information from a file with a different number or rows and columns?
Thank you!

Accepted Answer

Walter Roberson
Walter Roberson on 20 Apr 2021
t = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/589822/20200926T000414.txt');
t(1:5,:)
ans = 5×7 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7 __________ ____________ ____ ____ ____ ____ ____ 19/09/2020 00:00:00.231 -0.6 -0.6 0.4 12.1 15.2 19/09/2020 00:00:10.220 -0.7 -0.6 0.4 12.1 15.2 19/09/2020 00:00:20.223 -0.6 -0.6 0.4 12.1 15.2 19/09/2020 00:00:30.230 -0.7 -0.6 0.4 12.1 15.2 19/09/2020 00:00:40.232 -0.6 -0.6 0.4 12.1 15.2
  18 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!