Borrar filtros
Borrar filtros

Reading structured bit24 file data with skip

6 visualizaciones (últimos 30 días)
John Bockstege
John Bockstege el 16 de Sept. de 2014
Editada: dpb el 17 de Sept. de 2014
Ok here is the gist of the problem:
File structure is a big Endian machine format with an array of 1600 numbers (matrix 100X16) stored as 24bit signed integers. After each block of 1600 values, a three character word is written and the pattern then repeats:
|1600 24bit words|XXX|1600 24bit words|XXX|...
I am attempting to read all of the data into a variable using this syntax:
d=fread(fid,[100,32],'1600*bit24=>int32',24);%read in blocks of 1600 values then 24 bit skip (8bits * 3 Characters)
This produces an (unexpectedly) sized data array "d" of 100X41 elements... What am I missing here? d should be 100X32?? further the data is "jumbled up" in the variable d.
The only way I am able to correctly read this file data is:
fseek(fid,0,'bof');%skip to start of file
%loop
d=fread(fid,[100,16],'bit24'); %read in block of 1600 data points
fseek(fid,3,'cof');%skip over 3 bytes of characters and
%repeat from loop...concatenating d with another variable to contain all data (D=[D;d]) for example
This method is S L O W but works. Why doesnt the 'skip' form of fread work correctly?
Any Help is appreciated!
  1 comentario
dpb
dpb el 16 de Sept. de 2014
Editada: dpb el 17 de Sept. de 2014
Looks like should, granted. I'd suggest sending a small file that demonstrates the problem to official TMW support at www.mathworks.com
To speedup the workaround, preallocate D to a suitable size and populate it in the loop instead of using dynamic reallocation by concatenation as you're showing, ie, sotoo--
...
D=zeros(100,32,'int32');
while ~feof(fid)
D(i,:)=fread(fid,[100,16],'bit24');
i=i+1;
...
ADDENDUM
Have you tried memmapfile? I'm not positive it has the flexibility for the 24bit/3byte fields or not, but you might check...
Note: On looking, memmapfile doesn't have the bitN datatype, unfortunately, so it's of no help...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by