concatenate multiple blocks of CSV's with empty rows
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
And_Or
2020-6-5
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.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!