MATLAB Spoken Here

If You Know Your History, You Can Repeat It 3

Posted by Michael Katz,

It’s been a long time since we covered the Command History in the Desktop, so I thought I would remind everyone that it’s not just a pretty record of what you’ve done in the command window. You can use the history to selectively re-evaluate your previous commands! One of the ways that I use MATLAB is to try out several commands until I get the sequence that I want. I’ll often iterate through combinations of parameters until the desired output is reached. I’ll then want to group a sequence of correct commands into a reusable set. The Command History is the perfect tool to fit this workflow.

Double-clicking any line in the history will run that command again. You can also drag one or more lines from the history into the Command Window to run them in sequence. Or, instead of running those commands immediately, you can drag them to the editor to add those lines to the open MATLAB-file or drag them to the Shortcuts toolbar to create a new shortcut.

To make selection of multiple commands easier, you can delete intermediary commands from the history, so all that’s left are the commands you’re interested in. Then it’s easy to drag a selection, and you are ready to re-use those commands. You can also use the standard shift-click (or command-click) gestures to select multiple lines.

Finally, you can use the context menu to create a new shortcut, MATLAB file, run those commands, or profile them.

3 CommentsOldest to Newest

I use the command history very frequently in my work. One limitation that has annoyed me for many years is its hard-coded max storage size of 30KB, if I remember correctly. In this day and age when memory and disk space are measured in GB, I would really like to have the ability to increase this size.

I just add this to my startup.m file:

if sum(get(0,’ScreenSize’))>4
diaryname=[datestr(fix(clock),’yyyy-mm-dd HHMM’),’.log’];
diary(diaryname);
clear diaryname;
end

Complete history per session saved in a log file. Easy to use your OS’s search functionality to locate specific parts. One annoyance is that it captures the output as well (forgot to put a semicolon? have a bunch of debug/progress statements? That’ll put lots of junk in those logs). But the output can be useful at times, and I’m certainly not lacking drive space…

I test the screensize so that I avoid generating logs for MATLAB “sessions” that were just started to run a few things and return results for external scripts. I only want the logs for the sessions where I’m doing the typing.

These postings are the author's and don't necessarily represent the opinions of MathWorks.