Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Finding Text in the Command Window

Introduction

You can search for specified text that appears in the Command Window, where the text is either part of input you supplied, or output displayed by the MATLAB software. After finding the text, you can copy and paste it to the prompt in the Command Window to run it, or into an M-file or other file.

For techniques to reuse previous statements and navigate in the Command Window, see also Recalling Previous Lines in the Command Window, and Completing Statements in the Command Window — Tab Completion. To find files and text in files, see Viewing Files and Folders.

Finding Text Currently Displayed in the Command Window

To search for specified text currently displayed in the Command Window, follow these steps:

  1. Select Edit > Find when the Command Window is active.

    The Find dialog box opens.

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

    .

  2. Complete the dialog box, and then click Find Next or Find Previous.

    The search begins at the current cursor position. MATLAB finds the text you specified and highlights it.

  3. Repeat step 2 to find another occurrence.

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

To search for the specified text in other MATLAB desktop tools, change the selection in the Look in field.

Increasing the Amount of Information Available for Searching in the Command Window

To increase the amount of information displayed in the Command Window so that more text is available for searching, follow these steps:

  1. Select File > Preferences > Command Window, and then increase the setting for the Number of lines in command window scroll buffer.

  2. Do not clear the Command Window.

    In other words, do not enter clc or select Edit > Clear Command Window.

Performing an Incremental Search in the Command Window

With the incremental search feature, the cursor moves to the next or previous occurrence of the specified text in the Command Window. It is similar to the Emacs search feature. To use the incremental search feature in the Command Window, follow these steps:

  1. Position the cursor where you want the search to begin.

  2. Begin the incremental search using one of the following, depending on your setting for the Command Window key bindings. (Available from File > Preferences > Keyboard.)

    • If you set the preference to MATLAB Standard (Emacs), press Ctrl+S

    • If you set the preference to Windows , press Ctrl+Shift+S

  3. To look for the previous occurrence, press Ctrl+R or Ctrl+Shift+R instead.

    An incremental search field, Inc Search, appears at the bottom of the Command Window and is preceded by F for a forward search, or R when you are looking for the previous occurrence (reverse search).

    Image of Command Window showing the incremental search field. Text in the Command Window consists of a 16x2 cell array, with  numeric data in column 1 and strings in column 2. The strings are names of cities: Berlin, Boston, London and so on.

  4. In the Inc Search field, type the text you want to find. For example, look for Boston.

    As you type the first letter, b, the first occurrence of that letter in the Command Window after the current cursor position is highlighted. For the example shown, the first occurrence of b is highlighted, the b in Berlin. Note that incremental search allows for case sensitivity — see Case Sensitivity in Incremental Search.

    When you type the next letter, the first occurrence of the text becomes highlighted. In the example, when you add the letter o to the b so that the Inc Search field now has bo, the bo in Boston becomes highlighted.

    • If you mistype in the Inc Search field, use the Back Space key to remove the last letters and make corrections.

    • After finding the bo, you can press Ctrl+W to complete that word. In this example, Boston appears in the Inc Search field.

  5. To find the next occurrence of Boston in the Command Window, press Ctrl+S. To find the previous occurrence of the text, press Ctrl+R

  6. If MATLAB beeps, it means either that the text was not found, or the search wrapped past the end (or beginning) of the Command Window and continued at the beginning (or end).

    • When the text is not found, Failing appears in the incremental search field. Modify the search term in the incremental search field and try again. Use Ctrl+G to automatically remove characters back to the last successful search. For example, if plode fails, Ctrl+G removes the de from the search term because plo does exist in the Command Window.

  7. To end the incremental search, press Esc (escape) or Enter, or any other key that is not a character or number.

    The Inc Search field no longer appears. The cursor is at the position where the text was last found, with the search text highlighted.

Incremental search is also available in the Editor — see Performing an Incremental Search in the Editor.

Case Sensitivity in Incremental Search

When you enter lowercase letters in the Inc Search field, for example, b, incremental search looks for both lowercase and uppercase instances of the letters, for example b and B. However, if you enter uppercase letters, for example, B, incremental search only looks for instances that match the case you entered.

In the example, enter bO in the Inc Search field and incremental search does not find any matching text.

Image of Command Window and incremental search field. The field shows Failing F Inc Search: followed by a lowercase b and an uppercase O. There is no text in the Command Window that contains a b followed by an uppercase O.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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