Continue reading file after inner loop completes?

조회 수: 2 (최근 30일)
Lev Mihailov
Lev Mihailov 2022년 2월 14일
댓글: Benjamin Thompson 2022년 2월 15일
Now I'm reading the file in the matlab environment, but there was a problem, I can't force the file to be read after the loop is completed. The file consists of four parts, my code reads the first part without problems, all sizes are written in the first part (the number of bytes to read), there is no such thing in other parts (but I know them)
fileID = fopen(fileName);
finfo=dir(fileName);
filesize=finfo.bytes;
reccount=uint64(0);
datcount=uint64(0);
datcount=1;
while (~feof(fileID)) && (ftell(fileID)<filesize)
reccount=reccount+1;
blocksize=fread(fileID,[1,1],'uint32');
lastblocksize=fread(fileID,[1,1],'uint32');
block=fread(fileID,[1,1],'uint32');
datasize=fread(fileID,[1,1],'uint32');
bitmask=fread(fileID,[1,1],'uint32');
DataMatrix1=fread(fileID,[datasize,1],'uint8');
if (block==0)&&(bitand(bitmask,2))&&(bitand(bitmask,8)) % this loop reads the first 220 bytes of each block
MyData(:,datcount)=DataMatrix;
datcount=datcount+1;
end
end
Now the file reads the first 20 bytes, and then makes a matrix out of 200 bytes. The structure of each group of blocks looks like this: blok(220,400,600,1000). How to continue reading bytes knowing their size (matrices should be obtained (with sizes of 400xN, 600xN values)?
I will be glad for any help

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 2월 14일
If feof returns true you are at the end of the file. You cannot read any more data.
  댓글 수: 2
Lev Mihailov
Lev Mihailov 2022년 2월 15일
I just don't understand the logic of further reading the file at all, i.e. recount = 400 (these are all values of blocks (220,420,1020,2020,2240 and further), datcount = 100 (this is the length of all blocks). That's right, but how do I read another 400 bytes after I read the DataMatrix(MyData)?
Benjamin Thompson
Benjamin Thompson 2022년 2월 15일
You will probably need to post the file, or a sample of it, with a complete description of how you are trying to read it.

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by