Skipping lines in text file

17 次查看(过去 30 天)
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