Writing several big matrices in the same file using fwrite
7 views (last 30 days)
Show older comments
Hello everyone. I need to create binary file with metadata in the first 64kb and matrices sequence (images) starting right after this 64kb. Usually i'l do it like
fseek(fileWriteId,0+32*1024,-1 );
fwrite(fileWriteId,sizeTLSI , 'uint64');
fwrite(fileWriteId,sizeX , 'uint64');
fwrite(fileWriteId,sizeY , 'uint64');
fwrite(fileWriteId,sampling*sizeBuffer , 'uint64');
fseek(fileWriteId, 0+64*1024,-1 );
fwrite(fileWriteId,frame1, 'uint16');
...
fwrite(fileWriteId,frameN, 'uint16');
Where frame - one (or two, it doesn't actually matter) dimensional array. Usually it works fine everywhere, however in matlab i found very strange thing: Namely it works when length of frame is quite small (around several thousands), but if i increase frame length (1280*1024 for example) - it overwriting meta data which i've put into first 64kb.
Anyone know what is wrong with me/Matlab? Or is there some kind of logic behind it?
Tested with Matlab 64x 2014b and 2013b
Test code:
clear all
%A=uint16(zeros(1,10000))+1; %work
A=uint16(zeros(1,100000))+1; %do not work
fileWriteId = fopen('tmp.mlf', 'w');
fseek(fileWriteId,0+32*1024,-1 );
fwrite(fileWriteId,5 , 'uint64');
fwrite(fileWriteId,1024 , 'uint64');
fwrite(fileWriteId,1280 , 'uint64');
fwrite(fileWriteId,1000 , 'uint64');
fseek(fileWriteId,0+64*1024,-1 );
fwrite(fileWriteId,A, 'uint16');
fclose(fileWriteId);
fileReadId = fopen('tmp.mlf', 'r');
fseek(fileReadId,0+32*1024,-1 );
tSize=fread(fileReadId,1,'*uint64')
xSize=fread(fileReadId,1,'*uint64')
ySize=fread(fileReadId,1,'*uint64')
tms=fread(fileReadId,1,'*uint64')
fclose(fileReadId);
Hope to get some answer :)
0 Comments
Answers (0)
See Also
Categories
Find more on Logical 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!