필터 지우기
필터 지우기

How to get details from header

조회 수: 6 (최근 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 CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by