How to get details from header
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
dpb
le 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.
Plus de réponses (1)
kubyk
le 6 Nov 2013
1 commentaire
dpb
le 6 Nov 2013
Modifié(e) : dpb
le 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... :(
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!