By Linda Chuss, MathWorks
If you have ever lost your Command History for an entire session due to a system failure, you can avoid this by changing your preferences to save the history throughout the session instead of only at shutdown. By default, MATLAB saves the Command History upon shutdown. If an abnormal termination like a power failure occurs, however, the history is lost. This is especially troublesome if you do not shut down MATLAB daily.
To avoid that problem, select File -> Preferences -> Command History. Set the Saving option to Save after n commands and click OK. For example, set n to 1. MATLAB then saves the history after every line you execute.
If you want a record of system output as well as input, use the diary function. To automatically use the diary for every session, put this function in your startup.m file. Also, consider the logfile startup option for automatically writing output to the specified file. For more information about the Command History and related features, see the online documentation in the Help browser, or follow these links: