how to read a large binary file(*.dat file format) and store it in another file?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I have a binary data in a *.dat file format (i.e temp.dat). Its a 4DVar data (i.e lat.,lon.,pressure and temp). how to read these data files in MatLab and store it in another file? I cannot attach these files here as it shows that files are unsupported. Please, help me to get the values of temperature from these file formats. If there is any toolbox to read these files, kindly help me regarding this. I have MatLab version "R2013a".
Thanks & regards
0 Commenti
Risposte (1)
Geoff Hayes
il 3 Set 2014
Girija - do you have four files, one for latitude, longitude, pressure and temperature? Or are all four pieces of information stored within the same file? Do you know how many (say) temperature values there are?
Since the data is in binary, you must know the data type of each element (integer, double, float, etc.) so check out using fopen to open the file, and fread to read the data in.
For example (and this is taken from the link to fread)
% open the file for writing
fid = fopen('temp.dat','wb');
if fid>0
% create a 5x5 matrix
A = magic(5);
% write the matrix data to file
fwrite(fid,A,'double');
% close the file
fclose(fid);
end
% open the file for reading
fid = fopen('temp.dat','rb');
if fid>0
% continue reading until end-of-file is reached
while ~feof(fid)
% read a double
dblVal = fread(fid,1,'double');
% do something with dblVal
if ~isempty(dblVal)
fprintf('dblVal = %f\n',dblVal);
end
end
% close the file
fclose(fid);
end
You can do more than just read in one element at a time (which can be slow) and so can read in multiple elements instead. See the documentation for fread for more details.
In the above code, we write double data to file, and so must read back in the same data type. You will have to do the same for your code given the data type of that data within the binary files.
7 Commenti
Geoff Hayes
il 4 Set 2014
Which website, because it might provide details on how the data files are constructed?
Do you have to download software to create the data, or do you run it from the web?
Vedere anche
Categorie
Scopri di più su Low-Level File I/O in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!