Readtable ignoring first X rows

131 views (last 30 days)
Matt Smith
Matt Smith on 30 May 2022
Commented: Voss on 30 May 2022
I am attempting to use readtable to import the attached file. There are 356 rows in the csv document but the first 55 are ignored, and readtable produces a table of 301x7. This is repeated on a number of similarly formatted csv files, with varying amounts of rows ignored.
I have been unable to identify why these rows have been ignored.
q_sectors = readtable('qualy_sectors.csv');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.

Accepted Answer

Voss
Voss on 30 May 2022
You can specify 'NumHeaderLines',0 in your call to readtable:
q_sectors = readtable('qualy_sectors.csv','NumHeaderLines',0)
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
q_sectors = 355×7 table
P16G56PROJamesKELLETT Var2 Var3 RoslandGoldRacingByCenturyMotorsport Var5 Var6 data _______________________________ ___________________________ ____ ____________________________________ ____ ____ ____ {'IDEAL LAP TIME : 46.521' } {'BEST LAP TIME : 46.521'} NaN {'DIFFERENCE : 0.000'} NaN NaN NaN {'LAP SECTOR 1' } {'SECTOR 2' } NaN {'LAP TIME MPH' } NaN NaN NaN {'1 - OUTLAP 85.4' } {'23.720 86.4' } NaN {'1:10.768 61.44' } NaN NaN NaN {'2 - 35.975 88.0' } {'23.542 68.9' } NaN {'59.517 73.06' } NaN NaN NaN {'3 - 35.050 77.1' } {'22.340 134.4' } NaN {'57.390 75.77' } NaN NaN NaN {'4 - 28.016 112.9' } {'18.767 135.0' } NaN {'46.783 (3) 92.95' } NaN NaN NaN {'5 - 27.868 112.9' } {'18.794 135.0' } NaN {'46.662 (2) 93.19' } NaN NaN NaN {'6 - 27.789 112.9' } {'18.732 135.2' } NaN {'46.521 (1) 93.47' } NaN NaN NaN {'P2 21 G56 PRO Josh RATTICAN'} {0×0 char } NaN {'Elite Motorsport' } NaN NaN NaN {'IDEAL LAP TIME : 46.881' } {'BEST LAP TIME : 46.881'} NaN {'DIFFERENCE : 0.000'} NaN NaN NaN {'LAP SECTOR 1' } {'SECTOR 2' } NaN {'LAP TIME MPH' } NaN NaN NaN {'1 - OUTLAP 85.0' } {'24.364 87.8' } NaN {'1:05.409 66.48' } NaN NaN NaN {'2 - 36.457 69.6' } {'22.528 98.2' } NaN {'58.985 73.72' } NaN NaN NaN {'3 - 36.315 75.6' } {'23.482 98.8' } NaN {'59.797 72.72' } NaN NaN NaN {'4 - 33.817 97.2' } {'IN PIT' } NaN {'3:17.839 P 21.98' } NaN NaN NaN {'5 - OUTLAP 86.5' } {'19.750 134.2' } NaN {'55.067 78.96' } NaN NaN NaN
Now the table has the right number of rows.
  2 Comments
Matt Smith
Matt Smith on 30 May 2022
This worked perfectly, thank you very much.
Do you know the rationale as to why readtable is detecting that amount of rows as a header?
Voss
Voss on 30 May 2022
You're welcome!
I'm not sure why readtable detected so many rows as header rows.

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!