How do I read in specific parts of a binary file?

11 visualizzazioni (ultimi 30 giorni)
Hi all,
I would like to simply read in a specific, pre-determined length of a binary file in MATLAB. The file is huge, and I cannot/don't want to simply read all of it at once.
I have looked at the 'skip' command within fread but I do not want to skip chunks, I just have one chunk that I want to read in, and be done with it.
How can this be done? (The file is an int16 .bin file).
For example: My file has 1e6 samples, and it int16. I want to ONLY read in the values from sample, say, 433,232, up to, 546,323. How can this be done?
Thanks

Risposta accettata

Oleg Komarov
Oleg Komarov il 9 Mag 2012
Use fseek and then fread.

Più risposte (1)

Walter Roberson
Walter Roberson il 9 Mag 2012
fseek(fid, OFFSET, 'bof')
OFFSET would start at 0 for the first byte of the file.

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by