Load text file into matlab

2 Ansichten (letzte 30 Tage)
Maud Hendriksen
Maud Hendriksen am 29 Okt. 2020
Kommentiert: Rik am 5 Nov. 2020
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

Antworten (1)

Rik
Rik am 29 Okt. 2020
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 Kommentare
Rik
Rik am 29 Okt. 2020
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 am 5 Nov. 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by