writing mfile using a mfile

2 次查看(过去 30 天)
Rajan
Rajan 2011-10-4
Can any one pls give an example on how to write into an mfile using a mfile i.e mscript ??

回答(2 个)

Jan
Jan 2011-10-4
This is not complicated:
FID = fopen(fullfile(tempdir, 'MyFunction.m'));
if FID < 0, error('Cannot open file'); end
fprintf(FID, 'function out = MyFunction(in)\n');
fprintf(FID, 'disp(in);\n');
fprintf(FID, 'out = clock;\n');
fclose(FID)
But creating M-files dynamically is a critical task. Are you really sure, that this is an efficient method to solve your problem?
  6 个评论
Matt Tearle
Matt Tearle 2011-10-4
With the single quote marks actually included, you mean?
fprintf(1, '''%s'' \n',a1{:});
Rajan
Rajan 2011-10-4
yea Matt figured it out.thank you for the comments.

请先登录,再进行评论。


Matt Tearle
Matt Tearle 2011-10-4
  2 个评论
Rajan
Rajan 2011-10-4
Thank you for the answer.
I am using R2009b.
Do u have any idea of how to do it in R2009b?
Jan
Jan 2011-10-5
Editor = com.mathworks.mlservices.MLEditorServices;
methods(Editor)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by