fprintf matlab code example
Example 1: fprintf in directory matlab
fid = fopen('C:\abcd.txt','w+');
fprintf(fid, '%s\n', 'SampleText');
fclose(fid)
Example 2: save a text matlab
fileID = fopen('A.txt','w');
fprintf(fileID,'%15s %15s %15s\r\n','x','y','z');
nbytes = fprintf(fileID,'%15d %15d %15d\n',A)
fclose(fileID);
Example 3: fprintf matlab
A1 = [9.9, 9900];
A2 = [8.8, 7.7 ; ...
8800, 7700];
formatSpec = 'X is %4.2f meters or %8.3f mm\n';
fprintf(formatSpec,A1,A2)