필터 지우기
필터 지우기

Reading structured bit24 file data with skip

조회 수: 6 (최근 30일)
John Bockstege
John Bockstege 2014년 9월 16일
편집: dpb 2014년 9월 17일
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
dpb
dpb 2014년 9월 16일
편집: dpb 2014년 9월 17일
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...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by