%% Get Number of Bytes Written to File
% Write data to a file and return the number of bytes written.
% Write an array of data, A, to a file and get the number of bytes that fprintf writes.

A = magic(4);

fileID = fopen('myfile.txt','w');
nbytes = fprintf(fileID,'%5d %5d %5d %5d\n',A)

% The fprintf function wrote 96 bytes to the file.
%
% Close the file.

fclose(fileID);

%
% View the contents of the file with the type command.

type('myfile.txt')

% Copyright 2015 The MathWorks, Inc.