Overwriting a diary file

57 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2019-5-12
dfile ='Output.txt';
if exist(dfile, 'file') ; delete(dfile); end
diary(dfile)
diary on
  5 个评论
Walter Roberson
Walter Roberson 2019-6-26
It would probably be a good idea to fully qualify the diary file name, in case you are not in the same active directory that you think you are.
Jimmy Neutron
Jimmy Neutron 2020-10-29
@Andrew Robison If you add
diary off
at the end of your .m file, everything works fine

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by