fread file with 4 bytes of prepended array size
Show older comments
How do I read in a binary file(fread function) with data that has 4 bytes of data that specify the array size for each group of data. For example if I load the file using fread it would be 100x20 matrix but the first 4 bytes specify the area size(16 bytes). The file should read as 100x16. I'm currently using a for loop to read the file as start at byte 5, read 16, then start at byte 20, read 16, etc. Seems like their should be one line of code that says skip first 4 bytes of each data set. Thank you.
Answers (1)
Sean de Wolski
on 7 Feb 2012
0 votes
Yes, fseek will be your friend.
2 Comments
A
on 7 Feb 2012
Sean de Wolski
on 7 Feb 2012
preallocating A to its final size would be good. Why not just read all of the file in at once and reshape() after?
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!