How to generate an m-file only with MATLAB codes?

I want to generate an m-file only with MATLAB codes. Can any experts help me with it?
For example, the whole process can contain two steps: 1) create an m-file called abc.m,
2) write three lines in the file a = 1; b = 2; c = a + b;
How can I do that? By the way, I got two operating systems for MATLAB R2013a (8.1.0.604): - PC, Windows 7 - Mac, OS X (10.9.3)
Thanks in advance!

 채택된 답변

ES
ES 2014년 6월 19일
편집: ES 2014년 6월 19일

0 개 추천

fName= 'abc.m';
fid = fopen(fName,'a'); %a for append, you can use 'w' instead to write freshly
fprintf(fid ,'%s\n','a = 1; b = 2; c = a + b;'); % '%s is for string
fclose(fid);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Adding custom doc에 대해 자세히 알아보기

제품

태그

질문:

2014년 6월 19일

댓글:

2014년 6월 19일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by