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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by