Read multiple text files and save the data into matrix

3 ビュー (過去 30 日間)
Kanakaiah Jakkula
Kanakaiah Jakkula 2016 年 1 月 8 日
コメント済み: Walter Roberson 2016 年 1 月 15 日
Hi
I have multiple text files (for example I have attaced here 2 files). I want to read them, and save the data into matrix. But I only want the data above the first dotted line (text left side to : in first column, and other data after : to the second column). Secondly, I want to save the data which is between two dotted lines (----). Again, the data under Item is in first column, and corresponding 3rd column in second column. Please help me some how to do this.

採用された回答

Ingrid
Ingrid 2016 年 1 月 8 日
if your file always has the same amount of lines you could do something like this (if not, you need to check where the ---- occurs)
for ii = 1:Nfiles
fid = fopen(fileNames{ii});
if fid == -1
error('Unable to open txtfile');
end
fileData1{ii} = textscan(fid,'%s %s','Delimiter',':','HeaderLines',1,21);
fileData2{ii} = textscan(fid,'%s %s %s','Delimter','\t','HeaderLines',2);
fclose(fid);
end
  5 件のコメント
Kanakaiah Jakkula
Kanakaiah Jakkula 2016 年 1 月 14 日
Kindly help
Walter Roberson
Walter Roberson 2016 年 1 月 15 日
Change
FileName{j}=FileList(i).name;
to
FileNames{j}=FileList(i).name;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by