How do I delete bytes from the end of a binary file?

8 views (last 30 days)
Phelix
Phelix on 28 Mar 2024 at 4:33
Answered: Walter Roberson on 28 Mar 2024 at 4:58
For context, I'm taking a binary file that includes a basic header of known formatting, an extended header of unknown formatting, and a series of data packets with known formatting, and removing some of the data packets. My idea is to duplicate the file, keep its basic and extended header, write the data packets that I wish to keep over the bytes encoding all the data packets, and then delete the remaining old data packet bytes following the newly overwritten data packet bytes. I'm not sure how to delete the remaining bytes.
I would just copy the headers with the data packets to keep to a new file, but since the extended header formatting is unknown and values are encoded in the headers with varying precision, I don't think this would work.

Answers (1)

Walter Roberson
Walter Roberson on 28 Mar 2024 at 4:58
Unfortunately MATLAB does not support any truncation operations for files.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!