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

10 vues (au cours des 30 derniers jours)
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Avr 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 commentaires
Walter Roberson
Walter Roberson le 11 Mai 2021
t.dt = t{:,1} + t{:,2};
refdata = [t(:, 'dt'), t(:,4)];
Remember Samu
Remember Samu le 12 Mai 2021
Thank you so much Walter, It worked!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by