read binary file into matrix
41 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a binary file, that is encoded as hex. If I use fread on it I get a 8192x1 double with values like these:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 69 48 48 50 50 69 55 50 54 57 09
these are hex values, so 69 is E for example. Now at the end there is an 09 (tab) and I would like that tab to indicate to go to the next cell in a matrix, so that when I read and process the file, I have all the data stored in a matrix. Now if this were a tab-indented file, I would just use importdata(...), but as it is in a binary, that I have to convert to a string, and then to a matrix, I can't figure out how to do it. Any ideas?
0 commentaires
Réponses (1)
Muthu Annamalai
le 4 Déc 2012
Modifié(e) : Muthu Annamalai
le 4 Déc 2012
Pay attention to the 'source' and 'precision' options to fread().
>> doc fread
is your friend
% Create the file
fid = fopen('magic5.bin', 'w');
fwrite(fid, magic(5));
fclose(fid);
% Read the contents back into an array
fid = fopen('magic5.bin');
m5 = fread(fid, [5, 5], '*uint8');
fclose(fid);
0 commentaires
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!