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
2018 年 11 月 29 日
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!