Programming |
Writing Binary Data
The fwrite
function writes the elements of a matrix to a file in a specified numeric precision, returning the number of values written. For instance, these lines create a 100-byte binary file containing the 25 elements of the 5-by-5 magic square, each stored as 4-byte integers:
fwriteid = fopen('magic5.bin','w'); count = fwrite(fwriteid,magic(5),'int32'); status = fclose(fwriteid);
In this case, fwrite
sets the count
variable to 25
unless an error occurs, in which case the value is less.
Reading Binary Data | Controlling Position in a File |
© 1994-2005 The MathWorks, Inc.