Contents Previous Next Subchapters

Writing Binary Files
Syntax bwrite
See Also: write , bread

If no arguments are present, the file currently open for binary writing is closed.

If one argument is present, the specified file is opened for binary output where file is a character row vector. If a file is already open for writing its is closed before file is opened.

If three arguments are present, the values in data are written to the file. The character row vector dtype specifies the type of data that is being written to the file and must be either "char", "int", or "real". The integer scalar nbyte specifies the number of bytes corresponding to each data value in the file. If dtype is "char", nbyte must be 1. If dtype is "int", nbyte may be 2 or 4. If dtype is "real", nbyte may be 4 or 8. The double-precision column vector data contains the values that are written to the file.

The function bwrite is linked according to the convention in linkdll . If you enter
     dll dll\sample.dll, bwrite
     file  = "temp.dat"
     data  = double({97, 98, 99, 100, 10})
     bwrite("char", 1, data)
     read(file, "char")
O-Matrix will respond
because the ASCII codes 97, 98, 99, 100, 10 correspond to the characters a, b, c, d, and NEW_LINE.