Main Content

Command History Window

Open Command History window

Description

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 the short date format for your operating system, followed by the statements from that session. Brackets in the left margin indicate statements that were processed as a group. A colored mark precedes each statement that generated an error.

MATLAB saves statements that run in the Command Window to the history fileHistory.xml.These statements include those you run using theEvaluate Selectionitem on context menus in tools such as the Editor, Command History window, and Help browser. By default, MATLAB automatically saves the command history file after each statement. The history file does not include every action taken in MATLAB. For example, changes to values in the Variables editor are not included in the Command History window. All entries remain until you delete them, or until the number of statements in the history file exceeds the number of statements 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 window saves 25,000 statements.

You can select entries in the Command History window, and then perform these actions for the selected entries. Some actions are not available inMATLAB Online™

Action

How to Perform the Action

Create a script from statements.

Select an entry or entries, and then right-click and selectCreate ScriptorCreate Live Script从上下文菜单中。The Editor opens a new file that contains the statements you selected from the Command History window.

Rerun previous statements.

Do one of the following:

  • Press the Up Arrow key (↑) until the statement you want appears at the prompt, and then pressEnter

  • Double-click an entry or entries in the Command History window.

  • Select an entry in the Command History window and pressEnter

To extend the selection to include multiple statements, pressShift+↑.

Copy statements to another window.

Select an entry or entries and then do one of the following:

  • SelectCopy从上下文菜单中。粘贴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 favorite command from statements.

Select an entry or entries, and then do one of the following:

  • Click theicon to the left of the selection. MATLAB creates a new favorite command in the defaultFavorite Commandscategory.

  • Right-click and selectCreate Favorite.The Favorite Command Editor opens with the selected entries added to theCodefield. Configure the desired fields and clickSave

For more information about favorite commands, seeRerun Favorite Commands

删除entries.

Select the entries to delete, and then right-click and select删除, or press the删除key. To recall a deleted entry, right-click and selectUndo Delete, or pressCtrl+Z

To delete all entries, click(orinMATLAB Online), and then selectClear Command History从上下文菜单中。You cannot recall entries deleted in this way.

Open the Command History Window

To open the Command History window with all history showing, in the Command Window, press the Up Arrow key (↑) or entercommandhistory.打开命令窗口,并显示一个历史specific statement, type any part of the statement at the prompt and then press the Up Arrow key. To change how MATLAB searches for results, click(orinMATLAB Online) and select from the available options includingMatch Anywhere,Match Beginning, andMatch Case

By default, the Command History window closes after a statement is selected or theEsckey is pressed. To keep the Command History window open, in the Command History window, clickand then select eitherDetachorDock.If the Command History window is closed while detached or docked, go to theHometab, and in theEnvironmentsection, clickLayout.Then, underShow, clickCommand Historyand select eitherDockedorPopup

To keep the Command History window open inMATLAB Online, go to theHometab, and in theEnvironmentsection, clickLayout.Then, underShow, clickCommand Historyand selectDocked

Examples

expand all

Use the Command History search feature to find and run previousplotstatements.

In the Command Window, run these statements to create two line plots.

x = 0:pi/100:2*pi; y = sin(x); plot(x,y) x1 = linspace(-2*pi,2*pi); y1 = sin(x1); y2 = cos(x1); figure plot(x1,y1,x1,y2)

Typeplotand then press the up-arrow key. MATLAB displays the Command History with all instances ofplothighlighted. The last run instance ofplot被选中。

Press the up-arrow key to select the previous run instance ofplotand pressEnter.MATLAB runs the statementplot(x,y)

Programmatic Use

expand all

commandhistoryopens the MATLAB Command History window when it is closed, and selects the Command History window when it is open.

Version History

Introduced before R2006a