Overwriting a diary file

조회 수: 93 (최근 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 CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by