read binary file into matrix
36 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Muthu Annamalai
il 4 Dic 2012
Modificato: Muthu Annamalai
il 4 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Large Files and Big Data in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!