How to input text file into matlab as an array

I have a large set of text files all of the same format. I need only the numerical data from these to be imported into matlab as an array, or as any other form so long as i can use it in my code.
I have attached an example of one of the files '15048.txt'.
Thanks

답변 (1개)

Guillaume
Guillaume 2018년 11월 29일

1 개 추천

Probably, the easiest:
opts = detectImportOptions('15048.txt'); %let matlab figure out most of the file format
opts.ImportErrorRule = 'omitrow'; %so that it ignores the last line
opts.ExtraColumnsRule = 'ignore'; %otherwise, it detects an extra variable that is not there
opts.VariableNames(2:5) = {'PRECIP', 'EVAP', 'TMIN', 'TMAX'}; %matlab can't reliably detect the variable names as they're split over two rows
data = readtable('15048.txt', opts)

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2018년 11월 29일

답변:

2018년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by