Reading structured bit24 file data with skip
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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 Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!