Main Content

Find Text in Command Window or History

Find Text in the Command Window

You can search for text in the Command Window, on the Command Window title bar, click the Command Window actions button , and then select Find. You also can use the Ctrl+F keyboard shortcut.

In the Find dialog box, enter the text that you want to search for. The search begins at the current cursor position. To search backward or forward through the text in the Command Window, use the Find previous and Find next buttons You also can use the Shift+F3 and F3 keyboard shortcuts. To show a list of previous searches, use the Down Arrow key.

MATLAB® finds the text you specified and highlights it.

Find and Replace dialog box with a box for entering the text to search for

Select a search option to change how the Command Window search for text.

OptionDescriptionKeyboard Shortcut
Match caseSearch only for text with the precise case of the search text.Alt+M
Whole wordSearch only for exact full-word matches.Alt+W
Regular expression

Search using a regular expression. For example, to find all the words in a file that contain the letter x, enter the expression \w*x\w* and select the Regular Expression button . To access the match within a replacement pattern, use the format $&. For example, to add the character * to all the words in a file that contain the letter x, enter the expression $&*.

To create a capture group, surround the characters that you want to group with parentheses. Then, to access the capture group within the regular expression, use the format \number, where number refers to the capture group number. Capture groups are numbered automatically from left to right based on the position of the opening parenthesis in the regular expression. To access the capture group within a replacement pattern, use the format $number. For example, to find duplicate words in a file using capture groups, use the expression (\w+)\s\1. Then, to replace the two words with just one of the words, use the expression $1.

To create a named capture group, use the format ?<name>, where name is the name of the capture group. Then, to access the named capture group, use the format \k<name> within the regular expression, or $<name> within a replacement pattern. For example, to find duplicate words using a named capture group, use the expression (?<myword>\w+)\s\k<myword>. To replace the two words with just one word, use the expression $<myword>.

Multiline search, including the use of the control characters \n and \r, is not supported. In addition, token operators, comments, and dynamic expressions are not supported. For more information about using regular expressions, see Regular Expressions.

Alt+X

You can increase the amount of lines available in the Command Window so that more text is available for searching. Doing so requires more memory. On the Home tab, in the Environment section, click Settings. Select MATLAB > Command Window, and then increase the setting for Number of lines in the command window scroll buffer.

Clearing the command window (for example, with the clc function), empties the scroll buffer. The cleared text is no longer available for searching. To clear your display in the Command Window without clearing the buffer, use the home function.

Find Text in the Command History

To search for text in the Command History, use the Command History panel. To open the panel, click the Command History icon in the sidebar. Then, use the Search field to perform a search.

The Command History panel searches backward and selects the previous entry that contains the sequence of letters you typed. To find the previous or next occurrence of the entry, use theUp Arrow and Down Arrow keys.

To enter the selected entry into the Command Window, press Enter. To clear the search field, press Esc.

See Also

|

Topics