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

Respuestas (1)

Guillaume
Guillaume el 29 de Nov. de 2018
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)

Categorías

Preguntada:

el 29 de Nov. de 2018

Respondida:

el 29 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by