Load text file into matlab

2 visualizzazioni (ultimi 30 giorni)
Maud Hendriksen
Maud Hendriksen il 29 Ott 2020
Commentato: Rik il 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

Risposte (1)

Rik
Rik il 29 Ott 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 Commenti
Rik
Rik il 29 Ott 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 il 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.

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by