Load text file into matlab

2 ビュー (過去 30 日間)
Maud Hendriksen
Maud Hendriksen 2020 年 10 月 29 日
コメント済み: Rik 2020 年 11 月 5 日
Hi all,
I have a lot of text files(.csv) which I want to load into matlab. The file consists first of data which has 16 columns and the data that I am interested in contains 86 columns and varying number of rows. When I load the data into matlab using 'readtable', I obtain 16 columns and the data I am interested in is not in correct order anymore as you might understand. Is there a way to avoid this? There is a word ('Devices') that I could look for where the important data starts.
Kind regards,
Maud

回答 (1 件)

Rik
Rik 2020 年 10 月 29 日
Without seeing an example of your files, we can't tell you how to tweak the syntax you're using with readtable. Adapting the syntax so it works for your files is the best option.
A worse option is reading all your files as text and doing the parsing with your own functions. You can get my readfile function from the FEX. If you are using R2017a or later, you can also get it through the AddOn-manager. Then you trivially can loop over every line in your file.
  3 件のコメント
Rik
Rik 2020 年 10 月 29 日
That file looks like you will need to write your own parser. Your initial post sounded like you could use the HeaderLines option to skip the first few lines (read the documentation if you don't understand what I mean).
Rik
Rik 2020 年 11 月 5 日
Regarding your now deleted comment ("Ok thank you, so there is not really an 'easy/quick' way of doing this?"):
You could split the sections and write each to a temporary file, after which you can try using automatic tools. I don't know if you would consider that easy.

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by