readHeader
Read file header
Description
Examples
Read the header data from a binary file using the readHeader
function.
Write a header, followed by the data to a binary file named myfile.dat
. The header is a 1-by-4 matrix of double precision values, followed by a 5-by-1 vector of single-precision values. The data is a sequence of 1000 double-precision values.
fid = fopen("myfile.dat","w"); fwrite(fid,[1 2 3 4],"double"); fwrite(fid,single((1:5).'),"single"); fwrite(fid,(1:1000).',"double"); fclose(fid);
Read the header using a dsp.BinaryFileReader
object. Specify the expected header structure. This structure specifies only the format of the expected binary file header and does not contain the exact values.
reader = dsp.BinaryFileReader("myfile.dat"); s = struct("A",zeros(1,4),"B",ones(5,1,"single")); reader.HeaderStructure = s;
Read the header using the readHeader
function.
H = readHeader(reader);
fprintf("H.A: ")
H.A:
fprintf("%d ",H.A);
1 2 3 4
fprintf("\nH.A datatype: %s\n",class(H.A))
H.A datatype: double
fprintf("H.B: ")
H.B:
fprintf("%d ",H.B);
1 2 3 4 5
fprintf("\nH.B datatype: %s\n",class(H.B))
H.B datatype: single
Input Arguments
Binary file reader object, specified as a dsp.BinaryFileReader
System object.
Output Arguments
Header structure of the binary file, returned as a structure. Each field of the
structure is a real matrix of a built-in type. For example, if you specify the
HeaderStructure
property of the
dsp.BinaryFileReader
object to
struct('field1',1:10,'field2',single(1))
, the object writes a
header formed by 10 double-precision values, (1:10), followed by one single precision
value, single(1). If you do not specify a header, the object returns an empty structure,
struct([])
.
Data Types: struct
Version History
Introduced in R2016b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)