Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Running Frequently Used Statement Groups with MATLAB Shortcuts

What Is a MATLAB Shortcut?

A MATLAB shortcut is an easy way to run a group of MATLAB language statements that you use regularly. Although like an M-file script, a shortcut is not an M-file. It need not be on the search path nor in the current folder when you run it, and MATLAB does not store it as an M-file.

You can create shortcuts that you run from the Start button or the shortcut toolbar, depending on your preferences.

MATLAB maintains shortcut information in the shortcuts.xml file. This file is located in the folder displayed when you type prefdir in the Command Window. It is unlikely that you will need to access this file, because MATLAB updates it automatically.

When to Use MATLAB Shortcuts

Create MATLAB shortcuts to:

Creating MATLAB Shortcuts — Tutorials

You can create a MATLAB shortcut to run from the desktop Start button, or from the shortcuts toolbar, as described in the tutorials that follow. Both tutorials create a shortcut for a project called the Sea Temperature project. For these tutorials, you 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 these statements. Then, you run the shortcut to execute all the statements with a single click. The statements are:

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

Creating MATLAB Start Button Shortcuts

To create a start button shortcut, follow these steps:

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

  2. Complete the Shortcut Editor 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. You can:

      • Enter them by typing.

      • Copy and paste them from a desktop tool—if prompts (>>) from the Command Window appear, MATLAB automatically removes them when you save the shortcut.

      • Drag them from a desktop tool.

      • Edit them, if necessary.

      The Callback field uses the Editor preferences for keyboard shortcuts, colors, and fonts.

    3. Assign a Category, which is like a folder for organizing shortcuts. For this example, specify sea_temp_project.

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

    5. Click Save.

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

      MATLAB adds the shortcut to the Shortcuts entry in the Start button.

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

Creating MATLAB Toolbar Shortcuts

This example assumes that you have the following statements in the Command Window:

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

Follow these steps:

  1. If the shortcuts toolbar is not currently on the desktop, choose Desktop > Toolbars > Shortcuts.

  2. Select statements from the Command Window.

    You can also select statements from the Command History Window or an M-file.

  3. Drag the selection to the desktop Shortcuts toolbar.

    This illustration shows highlighted statements being dragged from the Command Window to the toolbar.

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

  4. Create the shortcut by completing the Shortcut Editor dialog box:

    1. In the Label field, enter a name for the shortcut.

    2. In the Callback field, edit the selected statements, if necessary.

      If prompts (>>) from the Command Window appear, MATLAB automatically removes them when you save the shortcut.

    3. Do not change the Category field value, Toolbar Shortcuts.

      For the shortcut to appear on the toolbar, this value must remain as-is.

    4. In the Icon field, select an icon, or keep the default.

    5. Click Save.

    The shortcut icon and label appear on the toolbar. If you have more shortcuts on the toolbar than the desktop can display concurrently, use the drop-down list to access them all.

Running MATLAB Shortcuts

To run a shortcut, do one of the following:

All the statements in the shortcut Callback field execute. It is as if you ran those statements from the Command Window, although they do not appear in the Command History window.

Editing and Organizing MATLAB Shortcuts

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

  1. Open the Shortcuts Organizer dialog box, by doing one of the following:

    • Click the Start button and select Shortcuts > Organize Shortcuts.

    • From the shortcuts toolbar context menu, choose Organize Shortcuts.

    The Shortcuts Organizer dialog box appears. When you select a shortcut category in the dialog box, the Edit Shortcut button replaces the Rename Category button.

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

  2. To edit and organize shortcuts and categories, do one of the following:

    • Click buttons in the dialog box.

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

Customizing MATLAB Toolbar Shortcuts

For step-by-step instructions on how to add a shortcut to the toolbar, see Creating MATLAB Toolbar Shortcuts.

Default Toolbar Shortcuts

By default, the Shortcuts toolbar includes these two shortcuts:

If you want to remove one or both of these shortcuts, see Deleting MATLAB Shortcuts from the Toolbar.

Hiding MATLAB Shortcut Labels on the Toolbar

To hide the shortcut labels on the toolbar, and leave just the shortcut icon:

  1. Right-click in the Shortcuts toolbar.

  2. From the context menu, select Show Labels, to clear the check mark next to the item.

    Now, when you move the mouse over a shortcut icon, its label appears as a tooltip.

Displaying Hidden MATLAB Shortcut Labels on the Toolbar

To redisplay a shortcut label that you previously hid:

  1. Right-click on the Shortcuts toolbar.

  2. From the context menu, check the Show Labels item by selecting it. The label reappears on the toolbar.

Deleting MATLAB Shortcuts from the Toolbar

To remove a shortcut:

  1. Right-click the toolbar shortcut button.

  2. From the context menu. select Delete.

  3. Click OK in the confirmation dialog box.

Alternative Ways to Create MATLAB Shortcuts

In addition to the previously described ways to create shortcuts, you can do any of the following:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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