필터 지우기
필터 지우기

fread file with 4 bytes of prepended array size

조회 수: 3 (최근 30일)
A
A 2012년 2월 7일
편집: Matthew Phillips 2013년 10월 3일
How do I read in a binary file(fread function) with data that has 4 bytes of data that specify the array size for each group of data. For example if I load the file using fread it would be 100x20 matrix but the first 4 bytes specify the area size(16 bytes). The file should read as 100x16. I'm currently using a for loop to read the file as start at byte 5, read 16, then start at byte 20, read 16, etc. Seems like their should be one line of code that says skip first 4 bytes of each data set. Thank you.
  댓글 수: 1
A
A 2012년 2월 7일
This works, but is it possible to optimize this code:
fseek(fid,4,'bof');
A =(fread(fid,[4,4],'*uint8',0,'n')).';
p=4;
for i= 1:100
p=p+20;
fseek(fid,p,'bof');
temp = (fread(fid,[4,4],'*uint8',0,'n')).';
A = cat(3,temp, A);
end

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 7일
Yes, fseek will be your friend.
  댓글 수: 2
A
A 2012년 2월 7일
yea, i'm using fseek within a for loop
Sean de Wolski
Sean de Wolski 2012년 2월 7일
preallocating A to its final size would be good. Why not just read all of the file in at once and reshape() after?

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by