MATLAB Community

MATLAB, community & more

Finding items in the History or Current Directory browser 10

Posted by admin,

My Command History can get pretty large and I often find myself wanting to find a command I executed a couple of weeks ago (otherwise I may have to go find the command in the doc again). I used to have to hit ctrl-F and bring up the Find dialog to search through the history. While that works, it feels a bit heavyweight for the task at hand. Other options include scrolling around an looking for the command or using up arrow in the Command Window.

We added a new feature in R2007a that will help you find items in the Current Directory browser or Command History by typing right on these components. In past releases, these components only had one key type searching (i.e. they would only find the first letter of the key typed). Now, I can just start typing multiple keys the command in the history and the match is selected in the history. Below I typed “fig” and the most recent item that matches is selected. I can see what has been typed in the tooltip that appears at the top of the window.


I can keep typing to further search for the item.


If I find a match, but it is not the one I want, up arrow will take me to the next match. If I want to copy all of the or delete all occurrences, ctrl-a will select all of the matches. In this next screenshot, I hit ctrl-a (or command-a for fellow mac users) to select all the matches.


If no match is found, the tooltip will indicate that it did not find a match.


You can also search for files in the Current Directory browser with this new feature.


Let me know how you like this new feature.


Comments are closed.

10 CommentsOldest to Newest

Eric Sampson replied on : 2 of 10

In addition to what Kristin mentioned, there is also the feature that you can use ‘*’ as a wildcard character at the start and middle of your word searches:

*ure %matches figure
f*re %also matches figure

Eric Sampson

Tony B replied on : 3 of 10

I submitted this as a feature request a few months ago, but I thought I’d mention it here as well, since it is somewhat related. I have a set of commands that I run frequently, and I generally access them by typing the first few letters and then hitting up-arrow in the command window. An example of this type of command would be opening a database connection:
databaseConn = database(‘DatabaseName’, ”, ”);
which is both frequently used and typed in exactly the same way every time.

However, sometimes if I spend a lot of time doing something else in matlab, or have more than one open for some reason, these “greatest hits” commands will cycle out of the command history buffer and I will have to type them in again in full. It would be nice if I could save these greatest hits to a separate file, and then matlab would make sure they were always available in the command history.


Kristin replied on : 4 of 10

I would suggest selecting the commands and dragging them up the shortcuts toolbar so that they are saved and readily available. You can also select them and use the context menu to put them into a new M-file.

As for your suggestion, are you looking to save out a history file and the reopen it? Or, for a section of the history that had “saved” commands?

Tony B replied on : 5 of 10

Thanks very much for your reply. I could definitely save these commands somewhere else like the shortcut bar, but I find that using the technique of typing a few letters and then up-arrow is much faster and more convenient than moving to the mouse and clicking somewhere else.

Most of the time this works fine, because I use these commands often enough that they are generally available in the command history. However, since the history file is finite, they sometimes cycle out and are unavailable for the up-arrow trick. So what I would like is to ensure that these few “greatest hits” always appear in the command history, so that they are always available for the up-arrow trick.

Thanks again!

ps. If you get really excited about this, you can look at the technical support discussion where I eventually requested a new feature; the thread id from that email was 1-3JJ17N. They provided a script that attempted to accomplish this objective, but didn’t work for me.

Yair Altman replied on : 6 of 10

Mike – the command history is a very powerful tool. I constantly use it in the Command Window (with the arrow keys) to modify and re-invoke past commands, for example – with modified input parameters.

Unfortunately, the history file is limited to only 20-30KB of data. For me, this translates into just several hundred commands, only a few days’ worth – hardly enough.

Since disk space and memory are a non-issue nowadays, it would be most convenient if this limit was significantly increased or better still – become a configurable preference.


p.s. – I know there is a FEX utility that bypasses this problem ( but I was looking for a more built-in solution.

Ljubomir Josifovski replied on : 8 of 10

Somewhat related, when multiple instances of Matlab open at the same time: my impression is that Maltab loads the history.m file on open and then writes new version on close, destroying the existing history.m. When multiple instances are open only the history of last closed instance seem to survive, histories of the rest are lost. If this is true (maybe I am mistaken of how the feature works), then would be of some help if the previous version of the file are saved under backup names, or even better if the history file is always appended to and never overwritten (maybe the limited in-memory size will then become an issue?). I assume asking for a history merge would be asking too much. :-) Thanks for your help, Ljubomir

Mike replied on : 9 of 10


That is correct. When MATLAB exits, it overwrites the history (also the desktop layout, and many other things). The Desktop isn’t really designed to be in an environment with multiple MATLABs open at the same time. It’s not a trivial problem to solve as the histories are sensitive to order and session. You can probably write your own finish.m file to save a backup or merge histories that works with your platform.

Honestly, it’s not a problem we’re likely to spend time resolving, as we don’t get a lot of requests for it. If you want to make an official request, use our online tech support form. They may even help you with a finish.m script.

Ljubomir Josifovski replied on : 10 of 10

Thanks for the finish.m tip, most helpful. Yes, I can imagine *The* Deskop was not designed with muliple Matlabs open in mind. :-) Ljubomir