concatenate multiple blocks of CSV's with empty rows
2 views (last 30 days)
Show older comments
I would like to open a number of CSV files like the attached dummy example "MatLab_example_csv.csv" with varying data values in rows 8-45, exctract one column, say column A, with it's data label in row 7, and make a concatenated table whose columns are the extracted column A's from the original CSV's and save to CSV or XLSX like "MatLab_example_concatenated". The "MatLab_example_csv.csv" files have an empty row 5:
If I use "importdata" to import "MatLab_example_csv.csv" it stops importing at the empty row, omitting the data of interest:

If I use "readtable" to read "MatLab_example_csv.csv" the entire contents are read in but it looks like "readtable" assigns variable names to each column:

I can select the section from this table I want, but since I am selecting the same section (data in column A) from each CSV I will open, one way or the other each time it will have the same variable name:

If this is in a "while" loop in code, when it go to concatenate the section from the second CSV file into an agregated table "agg", I get error for having duplicate variable names:
>> agg=double.empty
>> agg=[agg t_sec];
>> agg=[agg t_sec];
Duplicate variable name: 'x_CSVA_01_01'.
Thanks in advance for suggestion how to read and concatenate the blocks from CSV's into one table!
3 Comments
And_Or
on 5 Jun 2020
If you use xlsread instead of importdata, it will return NaN values for your empty rows. You can also use readtable function, that will detect NaN values, and then convert tables to arrays.
Answers (0)
See Also
Categories
Find more on Tables 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!