Azzera filtri
Azzera filtri

Skipping lines in text file

17 visualizzazioni (ultimi 30 giorni)
Muhsin
Muhsin il 12 Ott 2017
Commentato: Guillaume il 13 Ott 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

Risposta accettata

Guillaume
Guillaume il 12 Ott 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 Commenti
Muhsin
Muhsin il 13 Ott 2017
The code still gives me one column in workspace :(
Guillaume
Guillaume il 13 Ott 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by