Documentation Center

  • Trials
  • Product Updates

Command History

What Is the Command History?

The Command History window displays a log of statements that you ran in the current and previous MATLAB® sessions. The Command History lists the time and date of each session in your operating system's short date format, followed by the statements for that session. Brackets in the left margin indicate commands that are processed as a group. A colored mark precedes each command that generates an error.

To view the command history, press the up-arrow key, ↑, in the Command Window. To retrieve a command using a partial match, type any part of the command at the prompt, and then press the up-arrow key.

To dock or detach the Command History window, click , and then select an option. To view the Command History if it is closed: on the Home tab, in the Environment section, click Layout. Then, under Show, click Command History and select either Docked or Popup.

MATLAB saves statements that run in the Command Window to the history file, History.xml. These statements include those you run using the Evaluate Selection item on context menus in tools such as the Editor, Command History, and Help browser. By default, MATLAB automatically saves the command history file after each command. The history file does not include every action taken in MATLAB. For example, modifications of values in the Variables editor are not included in the Command History. All entries remain until you delete them, or until the number of commands in the history file exceeds the number of commands to save, as specified in the Command History preferences. When the specified limit is reached, MATLAB automatically deletes the oldest entries. By default, the Command History saves 25,000 commands.

Use Command History Commands

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

Create a script from a statement or statements.

Select an entry or entries, and then right-click and select Create Script from the context menu. The Editor opens a new file that contains the commands you selected from the Command History window.

Rerun previous commands.

Do one of the following:

  • Press the up arrow key (↑) until the command you want appears at the prompt, and then press Enter

  • Double-click an entry or entries in the Command History window, or select an entry and press Enter.

To extend the selection to include multiple commands, press Shift+↑.

Copy statements to another window.

Do one of the following:

  • Select an entry or entries, and then select Copy from the context menu. Paste the selection into an open file in the Editor or any application.

  • Drag the selection from the Command History window to an open file or another application.

Create a shortcut from a statement or statements.

Do one of the following:

  • Select an entry or entries, and then right-click and select Create Shortcut from the context menu.

  • Drag the selection to the desktop Toolstrip. The Add Shortcut dialog box opens and the selected commands appear in the Callback field.

Delete Entries

Select the entries to delete, and then right-click and select Delete, or press the Delete key.

To delete all entries, click , and then select Clear Command History from the context menu. You cannot recall these entries.

Change the Command History Date Format

MATLAB uses your operating system's short date format to display dates in the Command History window. To change the date format, for instance from MM/DD/YYYY to DD/MM/YYYY:

  1. Change the short date format for your operating system as described in its documentation.

  2. Restart MATLAB.

      Note:   Clearing the command history deletes all entries from the Command History window. You can no longer recall those entries in the Command Window.

Command History Preferences

You can exclude statements from the command history and specify how many commands to save to the command history file, History.xml. MATLAB uses the command history file for both the Command History window and statement recall in the Command Window.

    Note:   When you exclude statements from the command history file, you cannot recall them in the Command Window, nor can you view them in the Command History window.

To set Command History preferences, on the Home tab, in the Environment section, click Preferences. Select MATLAB > Command History, and then adjust the preference options as described below.

OptionUsage
Save exit/quit commands

Save exit and quit commands in the command history.

Save consecutive duplicate commands

Save consecutive executions of the same statement in the command history.

  • With this option selected, if you run magic(5) two times in a row, the entries for magic(5) appear on separate lines in the command history.

  • With this option cleared, the command history retains only one entry for magic(5) and displays a tally of consecutive executions to the left.

Don't save history file

This option is useful when multiple users share the same machine. For example, the option prevents each user from viewing statements others have run.

Any entries predating the current session remain unless you first delete entries from the Command History window.

Save last n commands

Specify the number of commands to save.

Was this topic helpful?