18-2 ��������������������?

L׬OnŪg ASCII ΤGiɮסAݥ fopen ƨӶ}ɮסAϥλykpUG

fid = fopen(filename, permission)

䤤 filename ܱŪgɮצW١Apermission hܱɮ׶i檺Bz覡AiHOUC@rG

pGڭ̬ٲ fopen ĤGӿJ޼ơAh permission w]ȴNO rC

Hint
  • bLnq@~tΤUApermission rꥲݯGiɮש ASCII ɮסCҦpAYnŪGiɮסAh permission rꥲݬOrbAԱAib MATLAB OAJuhelp fopenvC
  • ƹWAfopen O䴩h permission rAŪ̥iJ uhelp fopenv o짹㪺TC

fopen ƶǦ^@ɮ׿ѽX]File Identifier^Aq`O@ӫDtơAڭ̥iΦѽXӹ惡ɮ׶iUŪgBzCpGǦ^ɮ׿ѽXO -1AhN fopen Lk}ɮסA]iOɮפsbAάOϥΪvӵLk}ҦɮסCYLk}ɮת]Ai fopen Ǧ^ĤGӤ޼ƨܿ~TCFw_A̦nbCϥ fopen ɡAըǦ^ fid O_ĭȡCbUCdҤAڭ̸յ۶}Ҥ@ӤsbɮסAæLX^ǪTG

Example 1: 18-ɮŪg/fopen01.m[fid, message] = fopen('no_such_file', 'r'); fprintf('fid = %d\n', fid); fprintf('message = %s\n', message);fid = -1 message = No such file or directory

ѤWzdҥiɮפsbɡA^Ǫ fid O -1AP message |]t~TCY}Ҧ\AhǦ^ fid O@Ӥj 2 ơAӥBǦ^ message O@ӪŦrAҦpG

Example 2: 18-ɮŪg/fopen02.m[fid, message] = fopen('fopen02.m', 'r'); fprintf('fid = %d\n', fid); fprintf('message = %s\n', message); fid = 5 message =

Hint
MATLAB ϥ fid=1 ӥNuзǿXv]Standard Output^Afid=2 Nuзǿ~Xv]Standard Error^,]bϥγo fid ȮɡAiHϥ fopen Ӷ}ɮסC

@ɮתŪgAi fclose ƨɮסAϥλykpUG

status = fclose(fid);

Y@QAfclose Ǧ^ 0CYLkQɮסAh fclose Ǧ^ -1C@뱡pUAbɮתŪgAYϥ fclose ɮסAHK}ɮ׹LhAytθ귽OC

Yn@Ҧ}ҪɮסAi fclose('all') άO fclose allC

Hint
}Ҥɮ׳OӮɪơA]ɶqnNL̸mj餧AH{IJvC


MATLAB{]pGJg