Filter löschen
Filter löschen

How to get details from header

6 Ansichten (letzte 30 Tage)
kubyk
kubyk am 5 Nov. 2013
Bearbeitet: dpb am 7 Nov. 2013
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.

Akzeptierte Antwort

dpb
dpb am 6 Nov. 2013
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 Kommentar
kubyk
kubyk am 6 Nov. 2013
It works as I wanted. Thank you so much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

kubyk
kubyk am 6 Nov. 2013
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 Kommentar
dpb
dpb am 6 Nov. 2013
Bearbeitet: dpb am 7 Nov. 2013
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... :(

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Standard File Formats finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by