reading binary files
Afficher commentaires plus anciens
I am trying to convert a binary file to ascii using the fopen/fread functions. The binary file is in 2 byte integer format with the first column unsigned and the next three columns signed. The format is little endian. Each column is stored with a multiplier of 40, 100, 100, and 100 respectively.
The code I am using is:
clear all; clc;
[FID, message] = fopen('file','rb','l')
precip = fread(FID, [32507,1], 'ushort=>float','l'); tmax = fread(FID, [32507,1], 'short => float','l'); tmin = fread(FID, [32507,1], 'short=>float','l'); wind = fread(FID, [32507,1], 'short=>float','l');
X = [precip/40, tmax/100, tmin/100, wind/100]
The script generates a 4 column matrix where the first 5 rows are:
0 2.96 13.20 24.33;
19.95 3.300 2.32 10.03;
1633.60 17.42 0 1.45;
7.45 3.68 30.16 1.04;
0 2.83 15.49 17.05;
However should be: 0.00 7.98 -1.92 2.98;
0.00 8.47 -2.55 3.32;
0.00 11.88 -0.33 3.20;
0.05 7.78 -1.08 3.03;
0.00 6.86 -4.15 3.00;
Any help with this matter would be greatly appreciated.
Thanks
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!