Main Content

Rerun Favorite Commands

Create and Run Favorite Commands

MATLAB® favorite commands (previously called command shortcuts) are an easy way to run a group of MATLAB language statements that you use regularly. For example, you can use a favorite command to set up your environment when you start working, or to set the same properties for figures you create.

To create a favorite command:

  1. On the Home tab, in the Code section, click Favorites and then click New Favorite. The Favorite Command Editor dialog box opens.

  2. In the Label field, enter a name for the favorite command. For this example, enter Setup Workspace.

  3. In the Code field, type the statements you want the favorite command to run. You also can drag and drop statements from the Command Window, the Command History Window, or a file. MATLAB automatically removes any command prompts (>>) from the Code field when you save the favorite command. When navigating using the keyboard, use Esc to move out of the Code field.

    For example, enter these statements:

    format compact
    clear
    workspace
    filebrowser
    clc
    

  4. In the Category field, type the name of a new category or select an existing category from the drop-down list. If you leave this field blank, the favorite command appears in the default Favorite Commands category.

  5. In the Icon field, select an icon.

  6. To add the favorite command to the quick access toolbar, select both the Add to quick access toolbar and Show label on quick access toolbar options.

  7. To run the statements in the Code section and ensure that they perform the desired actions, click Test.

  8. When you are done configuring the favorite command, click Save.

To run a favorite command, on the Home tab, click Favorites and then click the icon for the desired favorite command. All the statements in the Code field of the Favorite Command Editor execute as if you ran those statements from the Command Window, although they do not appear in the Command History window.

To edit a favorite command, click the Edit favorite command button to the right of the favorite command. To delete a favorite command, click the Delete favorite command button to the right of the favorite command. You also can right-click the favorite command and select Edit Favorite or Delete Favorite.

Organize Favorite Commands

You can organize your favorite commands by storing them in different categories.

To create a new category:

  1. On the Home tab, in the Code section, click Favorites and then click New Category. The Favorite Category Editor dialog box opens.

  2. In the Label field, enter a name for the category. For this example, enter My Favorite Favorites.

  3. In the Icon field, select an icon.

  4. To add the category to the quick access toolbar, select both the Add to quick access toolbar and Show label on quick access toolbar options.

  5. Click Save.

To move a category up or down in the list of categories, or to move a favorite command within a category, drag the category or favorite command to the desired location. You also can use the Move category to top and Move category to bottom buttons to the right of the category.

To change whether a single category or favorite command appears in the quick access bar, click the Add to quick access toolbar and Remove from quick access toolbar buttons to the right of the category or favorite command. In MATLAB Online™, right-click the category or command and select Add to quick access toolbar. To add all favorite commands to the quick access bar, on the Home tab, right-click Favorites and select Add to quick access toolbar.

To further configure which favorite commands and categories appear in the quick access bar, on the Home tab, in the Code section, click Favorites and then click Quick Access. Configuring the quick access bar is not supported in MATLAB Online.

Related Topics