readtable : set up the multiple lines of variables

15 views (last 30 days)
This is my data. The problem appeared at the following image. From the second column, it does not work.
I commanded,
filename = 'A001.txt';
data = readtable(filename,'NumHeaderLines',0,'VariableNamingRule','preserve');

Accepted Answer

Walter Roberson
Walter Roberson on 12 Oct 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/760511/A001.txt';
opt = detectImportOptions(filename, 'VariableNamingRule','preserve');
opt.VariableNamesLine = 1;
data = readtable(filename, opt);
data(1:2,1:10)
ans = 2×10 table
Date Timestamp Event_Log Trial Count Starting_Point_Pos_x Starting_Point_Pos_y Starting_Point_Pos_z Target_Point_Pos_x Target_Point_Pos_y Target_Point_Pos_z __________ _________ __________ ___________ ____________________ ____________________ ____________________ __________________ __________________ __________________ 2.0211e+13 3.0136 {0×0 char} 0 -0.1446 0.9182 0.4343 0 0 0 2.0211e+13 3.0245 {0×0 char} 0 -0.1446 0.9182 0.4343 0 0 0
  3 Comments
Walter Roberson
Walter Roberson on 12 Oct 2021
I recognized the structure of the first few lines from a previous discussion where I had solved reading the file, so I checked the previous questions they had posted and found the file.
https://www.mathworks.com/matlabcentral/answers/1468736-how-to-load-txt-file-using-readtable
They attached the file there. You can right click on the file link to get the url, and then copy the url into code.
C B
C B on 12 Oct 2021
Ohh i see referance from old question.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!