Go To Location in File

Navigate to a Specific Location

This table summarizes the steps for navigating to a specific location within a file open in the Editor. In some cases, different sets of steps are available for navigating to a particular location. Choose the set that works best with your workflow.

Go ToStepsNotes

Line Number

  1. On the Editor tab, in the Navigate section, click Go To

  2. Select Go to Line...

  3. Specify the line to which you want to navigate.

None

Function definition

  1. On the Editor tab, in the Navigate section, click Go To .

  2. Under the heading Function, select the local function or nested function to which you want to navigate.

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.

  1. In the Current Folder browser, click the name of the file open in the Editor.

  2. Click the up arrow at the bottom of Current Folder browser to open the detail panel.

  3. In the detail panel, double-click the function icon corresponding to the title of the function or local function to which you want to navigate.

Functions list in order of appearance within your file.

Function reference

  1. Click in any instance of the function name.

  2. Press Alt+Up or Alt+Down to go to the next or previous function reference, respectively.

Alt+Up and Alt+Down are the default keyboard shortcuts for the actions Go to Previous Underline or Highlight and Go to Next Underline or Highlight, respectively.

For more information, see Define Keyboard Shortcuts.

Variable reference

  1. Click in any instance of the variable name.

  2. Press Alt+Up or Alt+Down to go to the next or previous variable reference, respectively.

Code Analyzer Message

Press Alt+Up or Alt+Down to go to the next or previous code analyzer message, respectively.

Code Section

  1. On the Editor tab, in the Navigate section, click Go To .

  2. Under Sections, select the title of the code section to which you want to navigate.

For more information, see Divide Your File into Code Sections

  1. In the Current Folder browser, click the name of the file that is open in the Editor.

  2. Click the up arrow at the bottom of Current Folder browser to open the detail panel.

  3. In the detail panel, double-click the section icon corresponding to the title of the section to which you want to navigate.

Property

  1. In the Current Folder browser, click the name of the file that is open in the Editor.

  2. Click the up arrow at the bottom of Current Folder browser to open the detail panel.

  3. On the detail panel, double-click the property icon corresponding to the name of the property to which you want to navigate.

For more information, see How to Use Properties

Method

  1. In the Current Folder browser, click the name of the file that is open in the Editor.

  2. Click the up arrow at the bottom of Current Folder browser to open the detail panel.

  3. In the detail panel, double-click the icon corresponding to the name of the method to which you want to navigate.

For more information, see How to Use Methods

Bookmark

  1. On the Editor tab, in the Navigate section, click Go To .

  2. Under Bookmarks, select the bookmark to which you want to navigate.

For information on setting and clearing bookmarks, see Set Bookmarks.

Set Bookmarks

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.

To set a bookmark:

  1. Position the cursor anywhere on the line.

  2. On the Editor tab, in the Navigate section, click Go To .

  3. 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.

Navigate Backward and Forward in Files

To access lines in a file in the same sequence that you previously navigated or edited them, use and

Interrupting the Sequence of Go Back and Go Forward

The back and forward sequence is interrupted if you:

  1. Click .

  2. Click .

  3. 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.

For example:

  1. Open a file.

  2. Edit line 2, line 4, and line 6.

  3. Click to return to line 4, and then to return to line 2.

  4. Click to return to lines 4 and 6.

  5. Click to return to line 1.

  6. 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.

Open a File or Variable from Within a File

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.

Item

Action

Local function

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 open function on the selection, which opens the selection in the appropriate tool.

Text file

Opens in the Editor.

Figure file (.fig)

Opens in a figure window.

MATLAB variable that is in the current workspace

Opens in the Variables Editor.

Model

Opens in Simulink.

Other

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.

Was this topic helpful?