This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

diary

Log Command Window text to file

Syntax

diary
diary filename
diary off
diary on

Description

example

diary toggles logging on and off. When logging in on, MATLAB® captures entered commands, keyboard input, and text output from the Command Window. It saves the resulting log to the current folder as an ASCII text file named diary.

To see whether logging is on, type get(0,'Diary'). MATLAB returns either 'on' or 'off'.

example

diary filename saves the resulting log to filename. If the file already exists, MATLAB appends the text to the end of the file. To see the name of the current diary file, type get(0,'DiaryFile').

example

diary off disables logging.

example

diary on enables logging using the current diary file name.

Examples

collapse all

Create a diary file and record several statements and their output.

Enable logging and save the resulting log to myDiaryFile.

diary myDiaryFile

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

Input Arguments

collapse all

Log file name, 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 folder.

Limitations

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, if you enter this statement in the Command Window

    str = sprintf('%s%s', ...
       '<a href="matlab:magic(4)">', ...
       'Generate magic square</a>');
    disp(str)
    

    MATLAB displays

    However, the diary file, when viewed in a text editor, shows

    str = sprintf('%s%s', ...
       '<a href="matlab:magic(4)">', ...
       'Generate magic square</a>');
    disp(str)
    <a href="matlab:magic(4)">Generate magic square</a>

Tips

  • To view the contents of the diary file with syntax highlighting, use the type function.

Introduced before R2006a