You can search for text in your files using the Find & Replace tool.
Within the current file, select the text you want to find.
On the Editor or Live Editor tab, in the Navigate section, click Find , and then select Find....
A Find & Replace dialog box opens.
Click Find Next to continue finding more occurrences of the text.
To find the previous occurrence of selected text (find backwards) in the current file, click Find Previous on the Find & Replace dialog box.
To search for references to a particular function or variable, use the automatic highlighting feature for variables and functions. This feature is more efficient than using the text finding tools. Function and variable highlighting indicates only references to a particular function or variable, not other occurrences. For instance, it does not find instances of the function or variable name in comments. Furthermore, variable highlighting only includes references to the same variable. That is, if two variables use the same name, but are in different scopes, highlighting one does not cause the other to highlight.
Find references to a function or variable using automatic highlighting by following these steps:
In a file open in the Editor, click an instance of the variable you want to find throughout the file. MATLAB® indicates all occurrences of that variable within the file by:
Highlighting them in teal blue (by default) throughout the file
Adding a marker for each in the indicator bar
If a code analyzer indicator and a variable indicator appear on the same line in a file, the marker for the variable takes precedence.
Hover over a marker in the indicator bar to see the line it represents.
Click a marker in the indicator bar to navigate to that occurrence of the variable.
Replace an instance of a function or variable by editing the occurrence at a line to which you have navigated.
This image shows an example of how the Editor looks with variable highlighting enabled. In the
image, the variable
i appears highlighted in
sky blue, and the indicator bar contains three variable markers.
To disable automatic highlighting, go to the Home tab and in the Environment section, click Preferences. In MATLAB > Colors > Programming Tools, clear the Automatically highlight option.
To help prevent typographical errors, MATLAB provides a feature that helps rename multiple references to a function or variable within a file when you manually change any of the following:
|Function or Variable Renamed||Example|
Function name in a function declaration
Input or output variable name in a function declaration
Variable name on the left side of assignment statement
As you rename such a function or variable, a tooltip opens if there is more than one reference to that variable or function in the file. The tooltip indicates that MATLAB will rename all instances of the function or variable in the file when you press Shift + Enter.
Typically, multiple references to a function appear when you use nested functions or local functions.
MATLAB does not prompt you when you change:
To undo automatic name changes, click once.
Automatic variable and function renaming is enabled by default. To disable it:
On the Home tab, in the Environment section, click Preferences.
Select MATLAB > Editor/Debugger > Language.
In the Language field, select MATLAB.
Clear Enable automatic variable and function renaming.
You can search for, and optionally replace specified text within a file. On the Editor or Live Editor tab, in the Navigate section, click Find to open and use the Find & Replace dialog box.
You can find folders and file names that include specified text, or whose contents contain specified text. On the Editor or Live Editor tab, in the File section, click Find Files to open the Find Files dialog box. For details, see Find Files and Folders.
lookfor to search
for the specified text in the first line of help for all files with
.m extension on the search path.
When you perform an incremental search, the cursor moves to the next or previous occurrence of the specified text in the current file. It is similar to the Emacs search feature. In the Editor, incremental search uses the same controls as incremental search in the Command Window. For details, see Search Using Keyboard Shortcuts.
You can go to a specific location in a file, such as a line number or function definition, set bookmarks, navigate backward and forward within the file, and open a file or variable from within a file.
This table summarizes the steps for navigating to a specific location within a file open in the Editor and Live Editor.
Includes local functions and nested functions.
For both class and function files, the functions list in alphabetical order—except that in function files, the name of the main function always appears at the top of the list.
Functions list in order of appearance within your file.
For more information, see Divide Your File into Code Sections.
For more information, see Ways to Use Properties.
For more information, see Methods in Class Design.
For information on setting and clearing bookmarks, see Set Bookmarks.
The Details Panel and Bookmarks are not available in the Live Editor or in MATLAB Online™.
You can set a bookmark at any line in a file in the Editor so you can quickly navigate to the bookmarked line. This is particularly useful in long files. For example, suppose while working on a line, you want to look at another part of the file, and then return. Set a bookmark at the current line, go to the other part of the file, and then use the bookmark to return.
Bookmarks are not available in the Live Editor or in MATLAB Online.
To set a bookmark:
Position the cursor anywhere on the line.
On the Editor tab, in the Navigate section, click Go To .
Under Bookmarks, select Set/Clear
A bookmark icon appears to the left of the line.
To clear a bookmark, position the cursor anywhere on the line. Click Go To and select Set/Clear under Bookmarks.
MATLAB does not maintain bookmarks after you close a file.
To access lines in a file in the same sequence that you previously navigated or edited them, use and .
Backward and forward navigation is not supported in the Live Editor or in MATLAB Online.
The back and forward sequence is interrupted if you:
Edit a line or navigate to another line using the list of features described in Navigate to a Specific Location.
You can still go to the lines preceding the interruption point in the sequence, but you cannot go to any lines after that point. Any lines you edit or navigate to after interrupting the sequence are added to the sequence after the interruption point.
Open a file.
Edit line 2, line 4, and line 6.
Click to return to line 4, and then to return to line 2.
Click to return to lines 4 and 6.
Click to return to line 1.
Edit at 3.
This interrupts the sequence. You can no longer use to return to lines 4 and 6. You can, however, click to return to line 1.
You can open a function, file, variable, or Simulink® model from within a file in the Editor. Position the cursor on the name, and then right-click and select Open selection from the context menu. Based on what the selection is, the Editor performs a different action, as described in this table.
Navigates to the local function within the current
file, if that file is a MATLAB code file. If no function by that name exists
in the current file, the Editor runs the
Opens in the Editor.
Figure file (
Opens in a figure window.
MATLAB variable that is in the current workspace
Opens in the Variables Editor.
Opens in Simulink.
Not available in MATLAB Online.
If the selection is some other type, Open selection looks for a matching file in a private folder in the current folder and performs the appropriate action.