18-4 ������ ASCII ������

fprintf ƥiNƨ̮榡wrӼgJ ASCII ɮסAϥλykpUG

fprintf(fid, format, y)

䤤 fid OgJɮתѽX] fopen ͡^Aformat O榡wrAΥHwƼgɮת榡Ay hO MATLAB ܼơC`Ϊ榡wr꦳UCXءG

LUخ榡wriJ help fprintf ӱoԲӪuWCҦpAN@ڪgJ squareRootTable.txtAiJpUG

Example 1: 18-ɮŪg/fprintf01.mx = 1:10; y = [x; sqrt(x)]; fid = fopen('squareRootTable.txt', 'w'); fprintf(fid, 'Table of square root:\r\n'); fprintf(fid, '%2.0f => %10.6f\r\n', y); fclose(fid); dos('start squareRootTable.txt'); % } squareRootTable.txt

bWҤA%2.0f LX`e 2ABapơA %10.6f LX`e 10A]te 6 pƳC]Ū̥iѶ}Ҫ squareRootTable.txt ҤWzCL榡C^

sprintf ƩM fprintf ƪ\Aߤ@POAsprintf NƥHrΦǦ^AӤOgJɮסCҦpG

>> str = sprintf('log(%f) = %e\n', 2, log(2)) str = log(2.000000) = 6.931472e-001

bYΤWAiݭnΨȦsؿμȦsɮסCΨtΪȦsؿAi tempdirApUG

>> directory = tempdir directory = C:\Users\ROGERJ~1\AppData\Local\Temp\

}Ҥ@ȦsɮסAi tempnameApUG

>> filename = tempname filename = C:\Users\ROGERJ~1\AppData\Local\Temp\tpd8a0f416_427f_46de_9e3e_c8baf771a03f

Hint
tempdir M tempname ҶǦ^r|̧@~tΪܼƦөwA]PtΥi|ͤP^ǦrC

HUdҡANOQ tempname ͤ@ӼȦs HTML ɮסAMANɮܦbsC

Example 2: 18-ɮŪg/writeHTML.mfilename = [tempname, '.html']; fid = fopen(filename, 'w'); fprintf(fid, '<html><body>\n'); fprintf(fid, 'This is a test homepage written by MATLAB!\n'); fprintf(fid, '</body></html>'); fclose(fid); dos(['start ', filename]); % ҰʩM .html ۳sε{

ͤpUG

Hint
MATLAB p⵲GAXΦC]Table^ΦhCɮס]pvBnBʵe^ӧe{ɡAѺܳoǭp⵲GO@ZܡC


MATLAB{]pGJg