How to get details from header

11 ビュー (過去 30 日間)
kubyk
kubyk 2013 年 11 月 5 日
編集済み: dpb 2013 年 11 月 7 日
I have document which contains header and data. One part of header is useless so I skipped this but in the second part are some details which I would like to save as variables.
the first part of header
ABR Group Header ==================================
Group Number: 2
Records: 16
SigGen File #1: D:\data\BioSigData\signaly\Stdpipji33.sig
SigGen File #2:
Subject ID: LEcisty
Reference #1: usporadani1
Reference #2: ABR4ch
Memo:
Start Time: Mon Apr 08 11:14
End Time: Mon Apr 08 11:16
----------------------------------------------------
the second part of header
Record Number: 24
Aqu. Duration: 19.9885 ms
Onset Delay: 0 ms
No. Points: 488
No. Averages: 300
No. Artifacts: 0
Start Time: Mon Apr 08 11:15
SigGen Index: 253
Variables:
Frequency = 7999.98 Hz
Attenuation = 0 dB
Phase = 180 DegredB
Calibration = 0 dB
data
1.18025e-005
1.04013e-005
9.32095e-006
9.15802e-006
9.79093e-006
1.04253e-005
1.02769e-005
9.14981e-006
7.38618e-006
5.5122e-006
3.99292e-006
3.07316e-006
2.70889e-006
.
.
.
I would like save inormation about duration, frequency and number of points. I don't know, how to get this details from header. Regards.

採用された回答

dpb
dpb 2013 年 11 月 6 日
Looks like a fixed format so just count lines and use the textscan ability to be called multiple times on same file...
fid=fopen(filename,'r');
dur=textscan(fid,'Aqu. Duration: %f ms','headerlines',15);
pts=textscan(fid,'No. Points: %f','headerlines',1);
frq=textscan(fid,'Frequency = %f Hz','headerlines',1);
fid=fclose(fid);
May want to cast to variable from cell.
  1 件のコメント
kubyk
kubyk 2013 年 11 月 6 日
It works as I wanted. Thank you so much.

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

その他の回答 (1 件)

kubyk
kubyk 2013 年 11 月 6 日
So I get details from head and the data with this code:
filename = 'usporadani11.txt';
fid = fopen (filename, 'r');
dur=textscan(fid,'Aqu. Duration: %f ms','headerlines',14);
dur=dur{1};
pts=textscan(fid,'No. Points: %f','headerlines',1);
pts=pts{1};
frq=textscan(fid,'Frequency = %f Hz','headerlines',6);
frq=frq{1};
att=textscan(fid,'Attenuation = %f dB');
att=att{1};
fs=pts/(dur/1000);
data=textscan(fid, '%f', 'headerlines', 2);
data=data{1};
fclose(fid);
But I can have several this sets in one file. It looks: header1, data1, header2, data2...header16, data16. Still the same format. Is it possible to get this ? Regards
  1 件のコメント
dpb
dpb 2013 年 11 月 6 日
編集済み: dpb 2013 年 11 月 7 日
If it's fixed length or you can count the lines based on input in the headers, just keep on doing the same thing in a loop.
You can allocate additional cell arrays and concatenate the results or use named dynamic fields in a structure or convert the cell contents of the textscan call to an array and concatenate as storage mechanism depending on needs.
OBTW, you can save a step on the conversion--instead of
dur=textscan(fid,'Aqu. Duration: %f ms','headerlines',14);
dur=dur{1};
can write
dur=cell2mat(textscan(fid,'Aqu. Duration: %f ms','headerlines',14));
Would be nice to have the facility to return variables instead of only cells from textscan, but not to be... :(

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

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by