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

10 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Abr. de 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 comentarios
Walter Roberson
Walter Roberson el 11 de Mayo de 2021
t.dt = t{:,1} + t{:,2};
refdata = [t(:, 'dt'), t(:,4)];

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by