Effacer les filtres
Effacer les filtres

Skipping lines in text file

17 vues (au cours des 30 derniers jours)
Muhsin
Muhsin le 12 Oct 2017
Commenté : Guillaume le 13 Oct 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

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by