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

조회 수: 10 (최근 30일)
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!

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by