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
diaryfunction. Optionally, you can name the log filediarycreates. For example, enable logging and specify the log filename asmy_data.out.diarycreates the filemy_data.outand starts recording all entered commands, keyboard input, and text output from the Command Window.diary my_data.outDisplay 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 8Disable logging.
diary offDisplay the contents of
my_data.outusing thetypefunction.type my_data.outA A = 1 2 3 4 5 6 7 8 diary offOpen the
diaryfilemy_data.outin a text editor and remove extraneous text, if desired.