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.
Enable logging using the
diary
function. Optionally, you can name the log filediary
creates. For example, enable logging and specify the log filename asmy_data.out
.diary
creates the filemy_data.out
and starts recording all entered commands, keyboard input, and text output from the Command Window.diary my_data.out
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
Disable logging.
diary off
Display the contents of
my_data.out
using thetype
function.type my_data.out
A A = 1 2 3 4 5 6 7 8 diary off
Open the
diary
filemy_data.out
in a text editor and remove extraneous text, if desired.