필터 지우기
필터 지우기

Read a defined size block and skip a set size bytes in binary file

조회 수: 5 (최근 30일)
I am trying to read a defined size block (A) and skip 8 bytes repeatedly close to the end of a binary file. Also want to skip a set size of bytes (end_skip) at end of file.
Have tried in a several way, but it does not seem to work out correctly.
Any suggestions?

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 21일
precision = '*uint8';
block_count = A;
skip_size_in_bytes = 8;
data = fread(fid, [1 block_count], precision, skip_size_in_bytes);
"Also want to skip a set size of bytes (end_skip) at end of file."
I do not understand that part? When you reach end of file, there are no bytes available to skip.
  댓글 수: 2
Ivy Chen
Ivy Chen 2018년 3월 21일
Thanks. We will not read until end of file, only to (end - skip_end_bytes).
How do I combine this with what you have above?
Walter Roberson
Walter Roberson 2018년 3월 21일
Don't worry about it. fread() will stop when it gets to the end of file, returning the data that it was able to read. The file position for the purposes of ftell() will be left at the end of file, not at skip_size_in_bytes past the end of file.

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

추가 답변 (0개)

카테고리

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