Read a defined size block and skip a set size bytes in binary file
2 views (last 30 days)
Show older comments
Ivy Chen
on 21 Mar 2018
Commented: Walter Roberson
on 21 Mar 2018
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?
0 Comments
Accepted Answer
Walter Roberson
on 21 Mar 2018
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 Comments
Walter Roberson
on 21 Mar 2018
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.
More Answers (0)
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!