| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
fwrite(fileID, A)
fwrite(fileID, A, precision)
fwrite(fileID, A, precision, skip)
fwrite(fileID, A, precision, skip, machineformat)
count =
fwrite(...)
fwrite(fileID, A) writes the elements of array A to a binary file in column order.
fwrite(fileID, A, precision) translates the values of A according to the form and size described by the precision.
fwrite(fileID, A, precision, skip) skips skip bytes before writing each value. If precision is bitn or ubitn, specify skip in bits.
fwrite(fileID, A, precision, skip, machineformat) writes data with the specified machineformat. The skip parameter is optional.
count = fwrite(...) returns the number of elements of A that fwrite successfully writes to the file.
fileID |
One of the following:
| |||||||||||||||
A |
Numeric or character array. | |||||||||||||||
precision |
String in single quotation marks that controls the form and size of the output. The following table shows possible values for precision.
long and ulong are 32 bits on 32-bit systems, and 64 bits on 64-bit systems.
If you specify a precision of bitn or ubitn, and a value is out of range, fwrite sets all bits for that value. Default: uint8 | |||||||||||||||
skip |
Number of bytes to skip before writing each value. If you specify a precision of bitn or ubitn, specify skip in bits. Use this parameter to insert data into noncontiguous fields in fixed-length records. Default: 0 | |||||||||||||||
machineformat |
String that specifies the order for writing bytes within the file. For bitn and ubitn precisions, specifies the order for writing bits within a byte. Use this parameter when you plan to read and write to the same file on different systems.
Possible values are:
Windows systems use little-endian ordering, and most UNIX systems use big-endian ordering, for both bytes and bits. Solaris systems use big-endian ordering for bytes, but little-endian ordering for bits.
|
Create a 100-byte binary file containing the 25 elements of the 5-by-5 magic square, stored as 4-byte integers:
fid = fopen('magic5.bin', 'w');
fwrite(fid, magic(5), 'integer*4');
fclose(fid);fclose | ferror | fopen | fprintf | fread | fscanf
![]() | funm | fwrite (serial) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |