MATLAB Answers

Overwriting a diary file

86 views (last 30 days)
I want to save my output to .txt file. I have used
diary Output.txt
diary on
some code
diary off
It saves diary file in same directory. But when I run the same code again it writes the command window output under the previously saved content instead of overwriting. I want to overwrite the previous content and make a file having only single output.

Accepted Answer

Walter Roberson
Walter Roberson on 12 May 2019
dfile ='Output.txt';
if exist(dfile, 'file') ; delete(dfile); end
diary(dfile)
diary on
  5 Comments
Jimmy Neutron
Jimmy Neutron on 29 Oct 2020
@Andrew Robison If you add
diary off
at the end of your .m file, everything works fine

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by