writing mfile using a mfile
Afficher commentaires plus anciens
Can any one pls give an example on how to write into an mfile using a mfile i.e mscript ??
Réponses (2)
Jan
le 4 Oct 2011
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 commentaires
Rajan
le 4 Oct 2011
Walter Roberson
le 4 Oct 2011
fprintf(fid, '%s \n',a1{1});
Notice the {} instead of ()
Matt Tearle
le 4 Oct 2011
fprintf(fid, '%s \n',a1{:});
for extra vectorized bonus points :)
Rajan
le 4 Oct 2011
Matt Tearle
le 4 Oct 2011
With the single quote marks actually included, you mean?
fprintf(1, '''%s'' \n',a1{:});
Rajan
le 4 Oct 2011
Matt Tearle
le 4 Oct 2011
0 votes
You can programmatically interact with the MATLAB Editor using the API introduced in R2011a:
Catégories
En savoir plus sur Adding custom doc dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!