Log Command Window text to file
diary toggles logging on and off. When logging is on,
MATLAB® captures entered commands, keyboard input, and text output from the
Command Window. It saves the resulting log to the current folder as a UTF-8 encoded
text file named
diary. To ensure that all results are properly
captured, disable logging before opening or displaying the resulting log.
To see whether logging is on, type
get(0,'Diary'). MATLAB returns either
diary saves the resulting log
filename. If the file exists, MATLAB appends the text to the end of the file. To see the current
diary log filename, type
diary off disables logging.
diary on enables logging using the current
diary log file name.
If the current
diary log file name does not include a full
path, MATLAB redetermines the path of the file relative to the current folder every
time logging is enabled. If the current folder has changed since the last time
logging was enabled, MATLAB might save the log to a different file.
Log Statements and Output
Create a diary file and record several statements and their output.
Enable logging and save the resulting log to
Perform a calculation, and create and display a matrix of ones in the Command Window.
a = 1; b = sin(a); x = ones(4)
x = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Disable logging and display the log file in the Command Window.
diary off type myDiaryFile
a = 1; b = sin(a); x = ones(4) x = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 diary off
filename — Log filename
character vector | string
Log filename, specified as a character vector or string.
filename can include a full path or a path relative
to the current folder. Otherwise, MATLAB saves
filename in the current
filename does not include a full path, MATLAB redetermines the path of the file relative to the current
folder every time logging is enabled. If the current folder has changed
since the last time logging was enabled, MATLAB might save the log to a different file.
Because the output of
diary is plain text, the log file does not
exactly mirror what you see on screen:
The diary file does not include graphics (figure windows).
The diary file does not preserve syntax highlighting and font preferences.
The diary file shows hidden components in the Command Window, such as hyperlink information generated with
matlab:, in plain text. For example, enter this statement in the Command Window:
str = sprintf('%s%s', ... '<a href="matlab:magic(4)">', ... 'Generate magic square</a>'); disp(str)
MATLAB displays this in the Command Window:
However, the diary file, when viewed in a text editor, shows this text instead:
<a href="matlab:magic(4)">Generate magic square</a>
To view the contents of the diary file with syntax highlighting, use the
Introduced before R2006a