MATLAB® Shortcuts — Easily Run a Group of Statements

What Is a Shortcut?

A MATLAB® shortcut is an easy way to run a group of MATLAB language statements that you use regularly. First you create a shortcut that contains all the statements. Then you select and run the shortcut to execute all the statements it contains. Create, run, and organize shortcuts from the Start > Shortcuts menu or the desktop Shortcuts toolbar.

Differences Between Shortcuts and M-Files

A shortcut is like an M-file script, but unlike an M-file, a shortcut does not have to be on the search path or in the current directory when you run it. In addition, you can run the shortcut by selecting it from the Start button or desktop Shortcuts toolbar, which are readily accessible.

Although shortcuts run MATLAB language statements, they are not M-files and are not stored as M-files.

Examples of Useful Shortcuts

These are some examples of useful types of shortcuts:

Creating Shortcuts

This is an example of a shortcut you might create for a project you work on, the Sea Temperature project. When you work on that project, you might want to set up your environment in a certain way by running a series of MATLAB language statements. You create a shortcut called sea_temp_env, which contains the statements. Then when you work on the project, you run the shortcut to execute all of the statements with a single click. The statements are

more on
format long e
cd d:/mymfiles/sea_temp_project
clear
workspace
filebrowser
clc

To create a shortcut, perform the following steps:

  1. From the Start button, select Shortcuts > New Shortcut.

    The Shortcut Editor dialog box appears.

  2. Create the shortcut by completing the dialog box.

    1. Provide a shortcut name in the Label field, for example, sea_temp_environment.

    2. Put the statements in the Callback field as shown in the following illustration. Either type them in, or copy and paste or drag them from a desktop tool. Edit the statements as needed. The field uses the Editor preferences for key bindings, colors, and fonts. Note that if you copy the statements from the Command Window, the prompt appears in the shortcut, but MATLAB removes the prompt when you save the shortcut.

    3. Assign a category, which is like a directory for organizing shortcuts. Specify sea_temp_project. To add the shortcut to the shortcuts toolbar, select the Toolbar Shortcuts category.

    4. Use the default shortcuts icon , or select your own.

    5. Click Save. MATLAB automatically removes any Command Window prompts (>>) in the Callback field upon saving the shortcuts.

      Image of Shortcut Editor dialog box showing each field in the dialog box with the example values.

  3. MATLAB adds the shortcut to the Shortcuts entry in the Start button, and to the Shortcuts toolbar, if you selected that Category.

    After creating a shortcut, run it by selecting it from its category in the Start button. You can also run it from the Shortcuts toolbar if you selected the Toolbar Shortcuts category.

    MATLAB maintains shortcut information in the file shortcuts.xml. Type prefdir, and MATLAB displays the location of the file. Most likely, you will not need to access this file, as MATLAB updates the file automatically.

For more information on the options in the Shortcut Editor dialog box, click the Help button.

Additional Ways to Create Shortcuts

You can also use these methods to create shortcuts:

Running Shortcuts

To run a shortcut, select the shortcut name, for example, sea_temp_environment, from the Start > Shortcuts menu or from one of its category submenus. All of the statements in the shortcut Callback field execute. It is as if you ran those statements from the Command Window, although they are not reflected in the Command History window.

If you added a shortcut to the Shortcuts toolbar, you can run it by clicking its icon on the shortcuts toolbar.

Shortcuts Toolbar

The Shortcuts toolbar is an alternative to creating and running shortcuts via the Start button. To show or hide the shortcuts toolbar, use Desktop > Shortcuts Toolbar. To create and run shortcuts via the desktop Shortcuts toolbar, perform these steps:

  1. Select statements from the Command History window, the Command Window, or an M-file.

  2. Drag the selection to the desktop Shortcuts toolbar. The following illustration shows two statements being dragged from the Command Window.

    Image of MATLAB desktop showing two lines selected in the Command window being dragged to the Shortcuts toolbar to create a new shortcut.

  3. The Shortcut Editor dialog box appears. The Callback field contains the selected statements, which you can edit as needed. If prompts (>>) from the Command Window appear, note that MATLAB automatically removes them when you save the shortcut. The Category field is Toolbar Shortcuts, which you must retain in order for the shortcut to appear on the toolbar.

    Provide the Label, select an Icon, and click Save.

    The shortcut icon and label appear on the toolbar. If you have more shortcuts on the toolbar than can be displayed at once, use the drop-down list to access all of them. For more information, click the Help button in the Shortcut Editor dialog box.

  4. Click the icon on the Shortcuts toolbar to run the shortcut. You can also run the shortcut from the Start button by selecting it in the Toolbar Shortcuts category.

Image of Shortcuts toolbar in the MATLAB desktop showing the shortcut just added.

You can also add a shortcut to the desktop Shortcuts toolbar by right-clicking the toolbar and selecting New Shortcut. Complete the resulting Shortcut Editor dialog box. Assuming you maintain the Toolbar Shortcuts category, the shortcut appears on the toolbar. To change the order of the shortcuts on the toolbar, select Start > Shortcuts > Organize Shortcuts and move the shortcuts within the Toolbar Shortcuts category.

How to Add and What's New Shortcuts

The Shortcuts toolbar includes two shortcuts provided with MATLAB. The How to Add shortcut provides help about shortcuts and adding them to the Shortcuts toolbar. What's New displays the Release Notes documentation.

To remove the How to Add or What's New shortcut from the Shortcuts toolbar, choose a different category. For instructions, see Organizing and Editing Shortcuts.

If you do not want to keep these shortcuts, remove each one by right-clicking its toolbar shortcut button and selecting Delete from the context menu. Click OK in the confirmation dialog box to remove the shortcut.

Shortcut Labels on Toolbar

You can hide the shortcut labels on the toolbar. Right-click in the Shortcuts toolbar. From the context menu, select Show Labels, which clears the check mark next to the item. The shortcut icons appear on the toolbar without labels. When you move the mouse over a shortcut icon, its label appears as a ToolTip. To make labels display in the toolbar, right-click the toolbar and select Show Labels, which adds a check mark next to the item and displays the labels.

Organizing and Editing Shortcuts

To create categories for shortcuts, and to move, edit, and delete shortcuts, perform these steps:

  1. Select Shortcuts > Organize Shortcuts from the Start button. Alternatively, access it via the shortcuts toolbar context menu.

    The Shortcuts Organizer dialog box appears. When a shortcut category is selected in the dialog box, the Edit Shortcut button is replaced by the Rename Category button.

    Image of Shortcuts Organizer dialog box, showing two shortcuts in a user-created category.

  2. Use the buttons in the dialog box to edit and organize shortcuts and categories. You can also right-click an item and select an action from the context menu.

    Changes take effect immediately.

  3. Click Close.

For more information about using the Shortcuts Organizer dialog box, click the Help button.

  


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