www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/GetNumberofBytesWrittentoFileExample.m

    %% Get Number of Bytes Written to File  
% Write data to a file and return the number of bytes written.   

% Copyright 2015 The MathWorks, Inc.


%% 
% 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')