Importing data from multiple .dat files into an array

3 ビュー (過去 30 日間)
Victoria Dutch
Victoria Dutch 2020 年 3 月 16 日
コメント済み: Ameer Hamza 2020 年 3 月 16 日
I have several hundred .dat files (saved in folders of ~15 for each geographic location they represent) that I want to add to my structural array, with each column as a field:
ie. the column headed density becomes
TVC.Date.Location.SMP.Profiles.Number.density_smp
However, my .dat files have 4 rows of metadata and then the headers before the data I need starts.
I've created a filelist for the first folder containing the .dat files and then tried
% pit RP_04
cd 'G:\Uni_Work\PHD\Data\Trail Valley Creek\Winter 2018-19\January 2019\SMP\Processed\RP_04';
FileList39 = dir('*.dat'); % generate a list of filenames which can be used to generate locations of profiles
Data_and_Headers = importdata(FileList39(1), '\t');
I've tried "ImportData" and "ReadTable" which I saw suggested on here, and had no luck with either. Any suggestions?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 16 日
編集済み: Ameer Hamza 2020 年 3 月 16 日
Try readmatrix and specify the number of header lines
readmatrix(FileList39(1).name, 'NumHeaderLines', 5)
or readtable with
readtable(FileList39(1).name, 'HeaderLines', 5)
  4 件のコメント
Victoria Dutch
Victoria Dutch 2020 年 3 月 16 日
Thanks. I think this gets me half way there. How would I then save column from this double as matrices?
Ameer Hamza
Ameer Hamza 2020 年 3 月 16 日
Have you read the files using readmatrix or readtable? readmatrix already outputs a matrix, for readtable you can use table2array.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by