Read csv-style file with header and subtitle

8 ビュー (過去 30 日間)
Thomas Cimiega
Thomas Cimiega 2021 年 9 月 24 日
コメント済み: Thomas Cimiega 2021 年 9 月 24 日
I want to import a csv file in form of a string matrix including all rows (i.e. headers).
My file is usually formatted with two header lines and an changing amount of columns, see attached file. All cells are semicolon separated.
When I use readtable, Matlab format the csv header content, which is not helpful. It also skips the second header line (subtitle X_Y). Then I found readmatrix, but I also can not import the file with it as expected.
When I open the file with a double-click on the file in Matlab, I can select the import as string array and set the range manually to the whole table space (see image). And the result is exactly what I need, but I can not reproduce it as code. I also tried to export the code to realize the function, but this exported function expects to keep the same number of columns.
So I am desperately searching for a solution and thinking about realizing the import function by myself, but the execution should take much longer (the files usually have 10000 rows and 200 columns).
Hopefully, someone can help :)

採用された回答

Akira Agata
Akira Agata 2021 年 9 月 24 日
How about the following solution?
T = string(readcell('tableExample.csv'));
  1 件のコメント
Thomas Cimiega
Thomas Cimiega 2021 年 9 月 24 日
Thank you, that is a big step forward. I wasn't aware that string is cell compatible. One issue is remaining: It seems to be less performant than readtable. But I can live with that.
Thanks again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by