Creating a diary that is not appended to an existing one.

조회 수: 16 (최근 30일)
Tomy Duby
Tomy Duby 2015년 9월 30일
답변: Dave 2017년 11월 9일
According to Matlab documentation when turning on the diary it appends the commands to the existing diary of the same name. Is there a way not to append, that is to start the diary file afresh? Thanks Tomy

채택된 답변

Dave
Dave 2017년 11월 9일
To have the diary name with the date and time when starting use this command:
diary(['gd_diary_',datestr(now,'dd-mm-yy','local'),'_',datestr(now,'hh-MM-ss','local'),'.txt'])

추가 답변 (2개)

WAT
WAT 2015년 9월 30일
if (exist(filename))
delete(filename);
end
  댓글 수: 4
Tomy Duby
Tomy Duby 2015년 10월 5일
Jan and Walter,
Thanks for your comments. I investigated further the behaviour of Matlab. Here is a sample code that I prepared
%DIARY_DELETE_TEST
%
% History:
% Created TD, 2-oct-15
%
% ---------------------------------------------------------------------
fprintf( 'Turning on the diary\n' )
diary ( 'test_diary.txt' )
fprintf( 'The time now is %s\n', datestr( now ) )
fprintf( 'Turning off the diary\n' )
diary off
fprintf( 'Deleting the diary\n' )
delete( 'test_diary.txt' )
dir
end
It works fine, the test_diary.txt file is deleted at the end of this run.
However in my application I create a GUI, use it to manipulate some data and in this environment, even if I close all GUI related stuff, the diary file cannot be deleted from within the calling function.
I did not investigate further as I found a workaround.
Tomy
Walter Roberson
Walter Roberson 2015년 10월 5일
I would speculate that at the time you delete() that the current directory is no longer the same directory you created the diary in. Remember that it is always safer to fully-qualify file names.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2015년 9월 30일
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 9월 30일
You can use dir() to check the file location. You can use fileattrib to check the permissions.
Xiaodi
Xiaodi 2017년 9월 3일
I guess, before you delete mydiary.out file, you must
diary off
to close the diary process and then maybe you can delete this mydiary.out file, which is created by
diary('mydiary.out')

댓글을 달려면 로그인하십시오.

카테고리

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