| MATLAB® | ![]() |
| On this page… |
|---|
Going to a Function (Subfunctions and Nested Functions) |
Note See also Finding Text in Files. |
Select Go > Go To. In the resulting Go To dialog box, select the Line number option, enter a line number, and click OK. The cursor moves to that line number in the current M-file.
To go to a function within an M-file (either a subfunction or a nested function), select Go > Go To. In the resulting Go To dialog box, select the Function option, and then select an entry from the list of subfunctions and nested functions in the file. Click OK.

Functions in the list appear alphabetically by name. To order them by their position in the file, click the Line column heading. The list does not include functions that are called from the M-file, but only shows lines in the current M-file that begin with a function statement.
Alternatively, click the Show Functions button
on the toolbar. Then
select the subfunction or nested function you want to go to from the
list. For both class and function files, the functions are listed
in alphabetical order—except that in function files, the name
of the main function always appears at the top of the list.
For M-file scripts that contain cells for rapid code iteration or publishing, the Go To dialog box lists cell titles.
You can set a bookmark at a line in a file in the Editor so you can quickly go to the bookmarked line. This is particularly useful in long files. For example, while working on a line, if you need 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 go back to the bookmark.
To set a bookmark, position the cursor anywhere in the line and select Go > Set/Clear Bookmark. A bookmark icon appears to the left of the line.
![]()
To go to a bookmark, select Next Bookmark or Previous Bookmark from the Go menu.
To clear a bookmark, position the cursor anywhere in the line and select Go > Select/Clear Bookmark.
Bookmarks are not maintained after you close a file.
Use Go > Back (and Go > Forward) to go to lines you previously edited or navigated to in a file. The feature goes to the lines in the sequence you accessed them. As an alternative to the menu items, use the Back and Forward buttons on the toolbar.

For example, if you open a file and make changes at lines 3, 9, and 6, use Go > Back to return to line 9, then 3, then 1, and then use Go > Forward to go from 1 to 3 to 9 to 6, and then return to 3. Detailed instructions to accomplish this are:
Select Go > Back again to return to line 1, which is the first line you originally navigate to in a file by virtue of opening it.
Use Go > Forward to reverse the direction of the feature—select Go > Forward to navigate to line 3.
Reverse the direction of the feature again—select Go > Back to navigate to line 3.
Use Go > Back and Forward to go to lines you previously edited or navigated to via these features:
Feature | Examples | Notes |
|---|---|---|
Opening a file (first line in the file) | File > Open | None |
Changes made using text-editing tools | Delete key, or Text > Increase Indent | Edits made to a selection of lines are represented by the first line in the selection. Changes made using Cell > Insert Cell Divider and Cell > Insert Text Markup are not considered as having been previously navigated to. |
Changes made using Find and Replace | Edit > Find and Replace | Changes made using Replace All are not considered as having been previously navigated to. |
Find features | Edit > Find and Replace, Find Next, Find Previous, and Find Selection | None |
Incremental search | Ctrl+S and Ctrl+R | None |
Show Function button |
| None |
Opening a selection | File > Open Selection | None |
Go to | Go > Go To line number, function, or cell title | None |
Bookmark navigation | Go > Next Bookmark and Previous Bookmark | A line at which you Set/Clear Bookmark is not considered as having been previously navigated to. |
Hyperlink access | From warnings or errors in the Command Window, from Find Files results, and from reports like the Profiler | None |
Debugging navigation | Lines with breakpoints that were stopped at while running, and lines stepped to | A line at which you set a breakpoint is not considered as having been previously navigated to, unless it was actually stopped at during execution. |
Cell mode navigation | Cell > Next Cell and Previous Cell, and Cell > Evaluate Current Cell and Advance | Lines accessed using Cell > Evaluate Current Cell are not considered as having been previously navigated to. |
If you use Go > Back and Go > Forward, and then edit another line or navigate to another line using the list of features described in the above table, the Go > Back or Go > Forward feature sequence is interrupted. 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.
For example:
Use Go > Back to move back to line 4, and then back to line 2.
You could then Go > Forward to lines 4 and 6, or Go > Back to line 1.
Instead, make an edit at line 3. Now you cannot Go > Forward to lines 4 and 6 and you can only Go > Back to line 2 and then line 1.
Go > Back and Forward do not go to lines in closed files.
When you have a split screen display, Go > Back and Forward go to the view in which the line was originally navigated to or edited in. If you remove the split, Go > Back and Forward do not go to any lines that were visited in the lower (or right) view.
You can open a subfunction, function, file, variable, or Simulink® model from within a file in the Editor. Position the cursor in 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 the table that follows.
Selection | Action |
|---|---|
Subfunction | Cursor moves to the subfunction within the current M-file. If no subfunction by that name is found in the current M-file, the Editor runs the open function on the selection, which opens the selection in the appropriate tool, as shown for the other selection types in this table. |
M-file or other text file | Opens in the Editor. |
Figure file (.fig) | Opens in a figure window. |
Variable | Opens in the Variable Editor. |
Model | Opens in Simulink. |
Other | If the selection is some other type, Open selection looks for a matching file in a private directory in the current directory and performs the appropriate action. |
![]() | Appearance of an M-File — Making Files More Readable | Finding Text in Files | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |