No BSD License  

Highlights from
Auxiliary Functions for Reading and Writing of Binary Data

from Auxiliary Functions for Reading and Writing of Binary Data by Christopher
A set of helper functions for reading and writing of readily formatted binary data.

writebinary(fn, A, prec)
function [COUNT] = writebinary(fn, A, prec)
%WRITEBINARY writing binary data helper function.
%   WRITEBINARY(FN, D, PREC) writes the elements of matrix A to the
%   specified file FN. The data are written in column order. COUNT is 
%   the number of elements successfully written. 
%   PREC controls the form and size of the result.  See the list
%   of allowed precisions under FREAD.
%
%   % Example for write uint16 image I to the file img.raw:
%   writebinary('img.raw', I, 'uint16');
%
%   See also FREAD, FWRITE, READBINARY

%   Author(s): medical-image-processing.com

fid = fopen(fn, 'wb');
COUNT = fwrite(fid, A, prec);
fclose(fid);

Contact us at files@mathworks.com