Command History Window

Overview of the Command History Window

The Command History window displays a log of the statements most recently run in the Command Window. If you have an active Internet connection, you can watch the Command History video demo for an overview of the major functionality.

To show or hide the Command History window, use the Desktop menu. Alternatively, use commandhistory to open the MATLAB® Command History window when it is closed, or to select it when it is open. For details, see Arranging the Desktop.

Image of Command History window, showing some of its key features: the timestamp (marks the start of each session); the +/- for each session, (to show or hide its entries); and the context menu (to perform actions on selected entries).

MATLAB provides other options for viewing a history of statements. See also the following sections:

Command History File

The Command History window and the Command Window's feature for Recalling Previous Lines both use the command history file, history.m, which is stored in the same directory as preferences for MATLAB. Type prefdir in the Command Window to see the location of the file. The command history file is loaded when MATLAB starts, and it stores a maximum of 20,000 bytes, deleting the oldest entries as needed to maintain that size.

Statements saved to the history are those that run in the Command Window. This includes statements you run using the Evaluate Selection item on context menus in tools such as the Editor, Command History, and Help browser. The history does not include every action taken in MATLAB, however, For example, if you run the statement

a = 1:10

and then modify the value of a in the Variable Editor, there is no record in the history that you modified the value of a.

MATLAB automatically saves the command history file throughout the session according to the Saving preference you specified. You can choose to automatically exclude certain statements from being written to the command history file with the Settings preference. For details, see Preferences for Command History.

Viewing Statements in the Command History Window

The Command History window lists statements you ran in the current session and in previous sessions. The time and date for each session appear at the top of the history of statements for that session. Use the scroll bar or the up and down arrow keys to move through the Command History window.

Click - to hide the history for a session, and click + to show it. Select a timestamp to select all entries for that session. With a timestamp selected, you can press the + or - key on the numeric keypad to show and hide entries.

Using Statements from the Command History Window

You can select entries in the Command History window and then perform the following actions for the selected entries.

Action

How to Perform the Action

Run statements in the Command Window

Double-click an entry (entries) in the Command History window to execute the statement(s) in the entries. For example, double-click edit myfile to open myfile.m in the Editor/Debugger. You can also run the statements in an entry by right-clicking the entry and selecting Evaluate Selection from the context menu, or by selecting an entry and pressing Enter or Return.

Edit and run statements in the Command Window

Select an entry or entries and then select Copy from the context menu. Paste the selection into the Command Window. Alternatively, drag the selection to the Command Window.

Then in the Command Window, edit the statements, and press Enter or Return to execute them.

Copy statements to another window

Select an entry or entries and then select Copy from the context menu. Paste the selection into an open M-file in the Editor/Debugger or any application. Alternatively, drag the selection from the Command History window to an open M-file or another application.

Create an M-file from statement(s)

Select an entry or entries and then right-click and select Create M-File from the context menu. The Editor/Debugger opens a new M-file that contains the statements you selected from the Command History window.

Create a shortcut from statement(s)

Select an entry or entries and then right-click and select Create Shortcut from the context menu. Alternatively, drag the selection to the Shortcuts toolbar. The Shortcut Editor opens and the selected statements appear in the Callback field. For more information, see MATLAB® Shortcuts — Easily Run a Group of Statements.

Searching in the Command History Window

There are two types of search in the Command History window:

After finding an entry, you can copy and paste it into an M-file or any file, or you can right-click and select Evaluate Selection to run the entry.

Finding Next Entry By Letter

Type a letter in the Command History window. The Command History window searches backwards to find the last previous entry that begins with that letter as illustrated in this example:

  1. Position the cursor at anywhere in the Command History window.

  2. Type the first letters of the entry you want to find. For example, type my.

    The Command History window searches backwards and selects the previous entry that begins with the letters you typed; in this example, you typed my, and the Command History finds myfor.

    As you begin typing that a small yellow-background pop-up window, Search history for:, appears at the top of the Command History window. This window keeps track of your search target as you type additional letters to narrow the focus of your search.

    If the search finds a matching entry in a sessions that is collapsed, it expands the session and selects the entry.

  3. Now type an s to extend the search to mys. The Command History window continues to search backwards, stopping next at the function mysurf.

Finding Multiple Occurrences of the Entry.   You can use the up and down arrow keys to search for the next or the previous occurrence of the entry you just found.

When you press Ctrl and the up or down arrow key, each occurrence of the entry remains highlighted while you search for additional instances.

To highlight all instances of the entry, press Ctrl+A. In the example below, all instances of entries beginning with my are highlighted.

Finding Text

Select Find from the Edit menu to search for specified text using the Find dialog box. Complete the dialog box. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. Click Find Next or Find Previous to find another occurrence, or use the keyboard shortcuts F3 and Shift+F3. Find looks for visible entries only, that is, it does not find entries in collapsed nodes.

Image of Find dialog box. The Look in field shows Command History, indicating the find operation will look through the text in the Command History.

MATLAB beeps when a search for Find Next reaches the end of the Command History window, or when a search for Find Previous reaches the top of the Command History window. If you have Wrap around selected, it continues searching after beeping.

Change the selection in the Look in field to search for the specified text in other MATLAB desktop tools.

Printing the Command History Window

To print the contents of the Command History window, select File > Print or Print Selection. Specify options for printing by selecting File > Page Setup. For example, you can print the history with a header. For more information, see Printing and Page Setup Options for Desktop Tools.

The printed version is sized to fit the page. If there is a long statement in the Command History, the reduced page size might be difficult to read. As a workaround, either use Print Selection, where the long statement is not part of the selection, or remove any extremely long statements from the Command History before printing it.

Deleting Entries from the Command History Window

Delete entries from the Command History window when you feel there are too many and it becomes inconvenient to find the ones you want. All entries remain until you delete them, or until the command history file exceeds its maximum size, at which point MATLAB automatically deletes the oldest entries—see Viewing Statements in the Command History Window.

To delete entries in the Command History window, first select the entries to delete, using one of these methods:

Then right-click and select Delete selection from the context menu, or press the Delete key. A confirmation dialog box might appear; for more information, see Confirmation Dialogs Preferences.

To delete all entries, select Edit > Clear Command History, or select Clear Entire History from the context menu.

After deleting entries from the Command History window, you will not be able to recall those statements in the Command Window as described in Recalling Previous Lines.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS