Borrar filtros
Borrar filtros

Skipping lines in text file

17 visualizaciones (últimos 30 días)
Muhsin
Muhsin el 12 de Oct. de 2017
Comentada: Guillaume el 13 de Oct. de 2017
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

Respuesta aceptada

Guillaume
Guillaume el 12 de Oct. de 2017
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 comentarios
Muhsin
Muhsin el 13 de Oct. de 2017
The code still gives me one column in workspace :(
Guillaume
Guillaume el 13 de Oct. de 2017
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by