フィルターのクリア

Read a .txt or .dat file with multiple headers and commas?

3 ビュー (過去 30 日間)
rbme17
rbme17 2017 年 8 月 18 日
回答済み: Krishna Bindumadhavan 2017 年 8 月 21 日
Hi everyone,
So I'm dealing with several .dat files (which I can change to .txt if that'd be easier). I need to read all of the numbers and assign them to separate arrays based on the headers.
Here's a sample:
Fit Curve Aui
Xbit, Hz, Alg_lin
2, 5, 102
1, 1
0.110010, -0.002008, -0.044201, -0.002580, -0.003818, -0.000605, -0.000053, -0.000200,
0.000545, 0.000721,...
1, 2
0.241561, -0.000270, -0.070538, -0.002198, -0.004259, -0.000619, -0.000900, -0.000267,
-0.000049, 0.000532,...
1,3 ...
1,4 ...
1,5 ...
2,1 ... etc.
This goes on 5 times, twice. I need to ignore the initial header (first three lines) and pass the other sub headers (1,1), (1,2), and so on. I then need to save the data to a structure/large array. There are 204 points per sub header that need to be saved.
E.g.
struct(1,204,1,1) = 0.110010, -0.002008, -0.044201, -0.002580, -0.003818,...
struct(1,204,1,2) = 0.241561, -0.000270, -0.070538, -0.002198, -0.004259,...
I've been trying to use fscanf but I'm not very familiar with reading files, but need to extract this specific data. Can anyone lend me a hand?
Thanks in advance!
  1 件のコメント
per isakson
per isakson 2017 年 8 月 20 日
編集済み: per isakson 2017 年 8 月 20 日
"[...] .dat files, which I can change to .txt if that'd be easier" No need, .dat is fine.
"There are 204 points per sub header" I assume that these 204 data points take up several lines. You show a line with 8 columns. However, 204/8 is not a whole number.
  • How many lines?
  • Do all the lines have the same number of data points?
  • How many data points per line?

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

回答 (1 件)

Krishna Bindumadhavan
Krishna Bindumadhavan 2017 年 8 月 21 日
I have attached a MATLAB script file along with the corresponding data file (.txt) which extracts the data and stores it in an array which is indexed by the various sub-headers.
You may have to make some minor changes to the script (ex. specify the correct path of the data file , changing the number of data points to be read, etc.) to suit your particular application. The changes that have to be made are mentioned in the comments in the script.
Hope this helps!

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by