필터 지우기
필터 지우기

Skipping lines in text file

조회 수: 17 (최근 30일)
Muhsin
Muhsin 2017년 10월 12일
댓글: Guillaume 2017년 10월 13일
Hello, I have a text file called Acc that has two columns of data. The first has text and i want it to skipped. Can anyone help me solve it. I am a new user.
Here is how I load the data;
load 'Acc.txt';
time = Acc(:,1);
Acc_x = Acc(:,2);
Thank you
Muhsin

채택된 답변

Guillaume
Guillaume 2017년 10월 12일
Most likely, you could read the file very simply with:
t = readtable('Acc.txt');
which, if the first line is a header, should parse the header correctly and name the columns correctly. if that doesn't work you can always tell readtable to skip the first line:
t = readtable('Acc.txt', 'HeaderLines', 1);
Note that reading a file as a table is much better than popping variables with unpredictable names in your workspace.
  댓글 수: 5
Muhsin
Muhsin 2017년 10월 13일
The code still gives me one column in workspace :(
Guillaume
Guillaume 2017년 10월 13일
No, the code gives you one table, acc, with two columns. As I said:
"Use acc.Time to get the time column and acc.Acc_x to get the acceleration column."
By the way, there's a lot of empty lines in your text file that matlab interpret as NaNs. To remove this invalid entries
acc = rmmissing(acc);
You can clearly see that acc is a table with two columns (variables):
>> summary(acc)
Variables:
Time: 1400×1 double
Values:
Min 0.01
Median 7.005
Max 14
Acc_x: 1400×1 double
Values:
Min -0.22004
Median -0.0058509
Max 0.20067

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by