writing mfile using a mfile
1 次查看(过去 30 天)
显示 更早的评论
Can any one pls give an example on how to write into an mfile using a mfile i.e mscript ??
0 个评论
回答(2 个)
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
2011-10-4
With the single quote marks actually included, you mean?
fprintf(1, '''%s'' \n',a1{:});
Matt Tearle
2011-10-4
You can programmatically interact with the MATLAB Editor using the API introduced in R2011a:
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!