Overwriting a diary file

57 ビュー (過去 30 日間)
Karanvir singh Sohal
Karanvir singh Sohal 2019 年 5 月 12 日
コメント済み: Jimmy Neutron 2020 年 10 月 29 日
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 Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by