MATLAB Answers


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

Asked by Tomy Duby on 30 Sep 2015
Latest activity Answered by David
on 9 Nov 2017
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


Sign in to comment.



3 Answers

Answer by David
on 9 Nov 2017
 Accepted Answer

To have the diary name with the date and time when starting use this command:


Sign in to comment.

Answer by Walter Roberson
on 30 Sep 2015


Well, I tried the delete command. But for some reason it does not work for me: I get the following error message:
Warning: File not found or permission denied
You can use dir() to check the file location. You can use fileattrib to check the permissions.
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

Sign in to comment.

Answer by WAT
on 30 Sep 2015

if (exist(filename))


Show 1 older comment
so I guess
if (exist(Filename, 'file') == 2))
to be even safer then?
Jan and Walter,
Thanks for your comments. I investigated further the behaviour of Matlab. Here is a sample code that I prepared
% 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' )
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.
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.

Sign in to comment.