4.8

4.8 | 10 ratings Rate this file 20 Downloads (last 30 days) File Size: 1.27 KB File ID: #9291

Save Entire Command History

by Jonathan Snell

 

07 Dec 2005 (Updated 07 Dec 2005)

Maintains a complete record of the command history (Matlab only maintains the last 20k worth ...

| Watch this File

File Information
Description

'preserve_history.m' maintains a complete record of the command history (MATLAB only maintains the last 20k worth of commands, so old commands are lost).

To get it to run you need to create a copy of your 'history.m' file and rename it 'history_saved.m'. The path of the history file will be something like "C:\Documents and Settings\poi\Application
Data\MathWorks\MATLAB\R14SP3\"

There are paths you will need to change in 'preserve_history.m' depending on your installation directory and username on lines: 9,25,47.

Also attached are 'startup.m' and 'finish files.m' which call the preserve_history file and also restore MATLAB to the last working directory whenever it is started.

The attached files must all be copied to "...matlab_directory\toolbox\local\".

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
08 Dec 2006 Scott Freeman  
23 May 2007 Yair Altman

Excellent & simple implementation fixing a long-standing Matlab annoyance. The preserve_history file could use extra help comment about the usage. Also, should use the built-in prefdir built-in function so that users won't need to modify the file. Lastly, the feature of restoring the last used folder should be placed in a separate submission - it is irrelevant in this one. All this said, this is still a great submission.

31 May 2007 James Blake

It's a bit tricky to install---you need to modify preserve_history.m in several places. There should be a parameter at the top of the file to make it easier, unless you can automate it further. Adding finish.m and preserve_history.m to your path, rather than touching the matlab install files is important, since normal users can do this without disrupting any other usage. It could also do with some clearer help. All in all, it works well, though.

17 Jun 2009 Mason Freed

I'd post code if I could, but to make the preserve_history.m file not require customization, and work for multiple Matlab installations, just change lines 13, 29, and 51 to these:

13: [fid, err] = fopen(fullfile(prefdir,'history_saved.m'), 'r');
29: [fid, err] = fopen(fullfile(prefdir,'history.m'), 'r');
51: [fid, err] = fopen(fullfile(prefdir,'history_saved.m'), 'r+');

30 Jul 2009 Nathan Thern  
20 Feb 2010 Eric

I'm not sure why Matlab doesn't allow the command history size to be adjusted, but this is a must have.

I made a string variable "rootpath" (e.g. 'c:\users\poi\AppData\*etc*') and then used [rootpath,'history*.m'] on the three lines that need to be edited, I think this is an obvious change that I assume many people would use.

Thanks for the program. I was moving command histories from one computer to another; giving write permissions, and copying the old history to the new one plus history_save was a little difficult, but most competent users should be able to overcome this.

One word of caution: if there is an error in "history_preserved.m" then you'll have to crash matlab (from the task manager in Windows) to get it to restart because finish.m will keep returning an error and prevent the program from closing.

20 Feb 2010 Eric  
01 Mar 2010 mark95tt  
16 Jun 2010 Jie Zhang  
22 Sep 2010 Emile Demarteau

Thanks for this great contribution! I was looking for this functionality, and it works great!

@Eric I got around the error problem in finish.m by placing the history_preserved command in a try cath block. So finish.m will look like:

setpref('StartupDirectory','LastWorkingDirectory',pwd)
try
    preserve_history;
catch EM
    h=msgbox(EM.message,sprintf('Error: %s',EM.identifier),'error');
    uiwait(h);
    return
end

Now it won't 'hang' your matlab but just display an error dialog before closing.

29 Nov 2010 Mr Smart  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
command history Cristina McIntire 10 Dec 2008 17:15:07
preserve Cristina McIntire 10 Dec 2008 17:15:07
maintain Cristina McIntire 10 Dec 2008 17:15:07
record Cristina McIntire 10 Dec 2008 17:15:07

Contact us at files@mathworks.com