How to input text file into matlab as an array
Afficher commentaires plus anciens
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
Réponses (1)
Guillaume
le 29 Nov 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)
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!