Main Content

Write to a Diary File

To keep an activity log of your MATLAB® session, use the diary function. When enabled, diary logs entered commands, keyboard input, and text output from the Command Window to a UTF-8 encoded text file on your system.

For example, if you have the array A = [ 1 2 3 4; 5 6 7 8 ] in your workspace, you can use the diary function to save A and its contents to a text file.

  1. Enable logging using the diary function. Optionally, you can name the log file diary creates. For example, enable logging and specify the log filename as my_data.out. diary creates the file my_data.out and starts recording all entered commands, keyboard input, and text output from the Command Window.

    diary my_data.out
    
  2. Display the contents of the array you want to save, for example, A. You also can display a cell array or other MATLAB class.

    A
    A =
        1     2     3     4
        5     6     7     8
    
  3. Disable logging.

    diary off
    
  4. Display the contents of my_data.out using the type function.

    type my_data.out
    A
    
    A =
    
         1     2     3     4
         5     6     7     8
    
    diary off
    
  5. Open the diary file my_data.out in a text editor and remove extraneous text, if desired.

See Also

Functions

Related Topics