How can I combine binary data in memory, and use fwrite for only one time to write all the data?
Show older comments
I need to write some large data in multiple loops. Each time, the data being written by fwrite is very small, and the frequent usage of fwrite seems to slow down my code. Here's an example:
% For loop starts:
fwrite(fid,dataA,'uint32');
fwrite(fid,dataB,'uint16');
fwrite(fid,dataC,'char');
...
% For loop ends
Is it possible if I combine dataA, dataB, and dataC together, so I can use fwrite for only one time, which will very likely be quicker.
2 Comments
per isakson
on 7 Aug 2021
Edited: per isakson
on 7 Aug 2021
The documentation on fwrite() says:
precision — Class and size of values to write
'uint8' (default) | character vector | string scalar
which answers your question: No
per isakson
on 8 Aug 2021
The documentation on fopen() says:
permission — File access type
[...]
'A' Open file for appending without automatic flushing of the current output buffer.
'W' Open file for writing without automatic flushing of the current output buffer.
And see Improving fwrite performance
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands 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!