%% Write Binary Data to a File
% This example shows how to use the fwrite function to export a stream of binary data to a file.
% Create a file named nine.bin with the integers from 1 to 9. As with any of the low-level I/O functions, before writing, open or create a file with fopen and obtain a file identifier.

fileID = fopen('nine.bin','w');
fwrite(fileID, [1:9]);

% By default, fwrite writes values from an array in column order as 8-bit unsigned integers (uint8).
%
% When you finish processing a file, close it with fclose.

fclose(fileID);

%
% Create a file with double-precision values. You must specify the precision of the values if the values in your matrix are not 8-bit unsigned integers.

mydata = [pi 42 1/3];

fileID = fopen('double.bin','w');
fwrite(fileID,mydata,'double');
fclose(fileID);

% Copyright 2015 The MathWorks, Inc.