Desktop Tools and Development Environment Previous page   Next Page

Tab Completion

MATLAB helps you automatically complete the name of a function on the search path, filename, variable, structure, or Handle Graphics property if you type the first few characters and then press the Tab key. To use tab completion, you must have the tab completion preference selected. For details, see Keyboard and Indenting Preferences for the Command Window.

These examples explain how to use tab completion:

Basic Example--Unique Completion

This example illustrates a basic use for tab completion. After creating a variable, costs_march, type

costs

and press Tab. MATLAB automatically completes the name, displaying

costs_march

Then complete the statement, adding any arguments and options, and press Return or Enter to run it. In this example, if you just press Enter, MATLAB displays the contents of costs_march. If MATLAB does not complete the name costs_march but instead moves the cursor to the right, you do not have the preference set for tab completion.

You can also use tab completion anywhere in the line, not just at the beginning. For example, if you type

a = cost

and press Tab, MATLAB completes costs_march.

Multiple Possible Completions

If there is more than one name that starts with the characters you typed, when you press the Tab key, MATLAB displays a list of all names that start with those characters. For example, type

cos

and press Tab. MATLAB displays

Image of Command Window showing multiple possible tab completions. After the prompt are the letters cos, next to which is a list of possible completions: cos, cosets, cosh, costs_march. By default, the first item in the list, cos, is highlighted.

The resulting list of possibilities includes the variable name you created, costs_march, but also includes functions that begin with cos, including cosets from the Communications Toolbox.

Continue typing to make your entry unique. For example, type the next character, such as t in the example. MATLAB selects the first item in the list that matches what you typed, in this case, costs_march. Press Enter or Return to select that item to complete the name at the prompt. In the example, MATLAB displays costs_march at the prompt. Add any arguments, and press Enter again to run the statement.

You can select from the list of possible completions using navigation keys such as up and down arrow keys, and Page Up and Page Down. You can clear the list without selecting anything by pressing Escape. Note that the list of possible completions might include items that are not valid commands, such as private functions.

Tab Completion for Directories and Filenames

Tab completion works for directories and filenames in MATLAB functions. For example, type

edit d:/<Tab>

MATLAB displays the list of directories and files in d, from which you can choose one. For example, type

mym<Tab>

MATLAB displays

edit d:/mymfiles/

where mymfiles is the only directory on your d drive whose name begins with mym. Continue using tab completion to display and complete directory names or filenames until you finish the edit statement.

Tab Completion for Structures

For structures, after the period separator, press Tab. For example, type

mystruct.<Tab>

to display all fields of mystruct. If you type a structure and include the start of a unique field after the period, pressing Tab completes that structure and field entry.

For example, type

mystruct.n<Tab>

which completes the entry mystruct.name, where mystruct contains no other fields that begin with n.

Tab Completion for Properties

Complete property names using tab completion, as in this graphics example. Here, f is a figure. Type

set(f, 'pap<Tab>

MATLAB displays

Image of possible tab completions for the paper property. The list consits of: PaperOrientation, PaperPosition, PaperPositionMode, PaperSize, PaperType, PaperUnits. By default, the first item, PaperOrientation is highlighted.

Select a property from the list. For example, type

u<Enter>

and MATLAB completes the property, including the closing quote.

set(f, 'paperunits'

Continue adding to the statement, as in this example

set(f, 'paperunits', 'c<Tab>

MATLAB automatically completes the property

set(f, 'paperUnits', 'centimeters'

because centimeters is the only possible completion.


Previous page  Recalling Previous Lines Keyboard Shortcuts in the Command Window Next page

© 1994-2005 The MathWorks, Inc.