Skip to Main Content Skip to Search
Product Documentation

Run MATLAB Files in the Editor

Run Files with No Input Arguments in the Editor

To run a MATLAB script or function file that is open in the Editor and requires no input argument values, do one of the following:

Run Files with Input Arguments in the Editor

To provide values for MATLAB function input arguments, create and use a run configuration. You can associate multiple run configurations with a function file to assign different input values. MATLAB saves the run configurations between sessions to a file named run_configurations.m. (For details, see About the run_configurations.m File.)

You can also use run configurations to provide preparatory or setup information before running a MATLAB file.

Create and Use a Run Configuration

This section demonstrates how to create and use a run configuration by stepping you through an example. The steps specify Editor toolbar buttons, but you can also use equivalent options in the Debug menu.

  1. Open collatzplot_new.m:

    edit(fullfile(matlabroot,'help','techdoc',...
    'matlab_env','examples','collatzplot_new.m'))
    

    Save the file to a folder for which you have write permission. In the example, the file is saved to I:\my_matlab_files\my_mfiles\collatzplot_new.m.

  2. Click the down arrow on the Run button in the Editor toolbar,

    Image of the Run button with the tooltip for the down arrow open, which reads: Select and run configuration.

    and then select Edit Run Configurations for collatzplot_new.m.

  3. In the MATLAB expression area of the Edit Configurations dialog box, replace the existing comment and text with:

    % For debugging purposes
    m=3;
    collatzplot_new(m)

    Image of MATLAB expression portion of the Edit Configuration dialog box.

  4. Click Run to execute the statements in the MATLAB expression field.

    collatzplot_new(3) runs, and a Figure window displays the plot.

  5. Change m = 3 to m = 3, and then click Run.

    You can also modify the code file, save the changes, and click Run.

  6. Click Close.

Use a Previously Created Run Configuration

After creating a run configuration, you can view and use the configuration without opening the Edit Configurations dialog box:

  1. In the Editor toolbar, click the down arrow on the Run button and position the mouse pointer on a run configuration name.

    The MATLAB desktop displays a tooltip showing the MATLAB Expression associated with the run configuration.

    Image of Editor with a file open and the Run button menu open. The tooltip is open showing the run configuration's MATLAB expression.

  2. Select a run configuration name.

    MATLAB runs the configuration.

Create and Execute Multiple Run Configurations for a File

You can create multiple run configurations for a given file, allowing you to run with different values for input arguments, each for a different purpose. Create a named run configuration for each purpose, all associated with the same file. Then, any time you open that file, choose and execute the run configuration you want. For example, for collatzplot_new(m) you might use three values for m and have three run configurations:

  1. In the Editor toolbar, click the down arrow on the Run button , and then select Edit run configuration for collatzplot_new:

    1. Select the file to which you want to add a run configuration, or select a configuration already associated with that file.

    2. Click the Add button (under the list of configurations), and then click Run Configuration.

    MATLAB creates a new default run configuration template, in this example, collatzplot_new_2.

    The example shows collatzplot_new_2 and its default expression, as well as one previously created run configuration associated with collatzplot_new.m, collatzplot_new.

    Image of Edit Configurations dialog box with two run configurations in the left pane.

  2. In the Edit Configurations dialog box, modify, run, and name the new run configurations as you did for the initial run configuration, collatplot_new, as described in Create and Use a Run Configuration.

    For example, rename collatzplot_new_2 to collatzplot_new_largevalue, and replace the default template expression with:

    % Large value
    m=200;
    collatzplot_new(m)
    

    To create another run configuration, click the down arrow next to the Add button again, and then click Run Configuration. Rename collatzplot_new_2 to collatzplot_new_random and replace the default template expression with:

    % Random value
    m=int16(rand*50);
    collatzplot_new(m)
    clear all
    
  3. Select a run configuration in the listing to see and modify its expression, or to rename the configuration.

  4. To get a quick view of the expression in a configuration, position the mouse pointer on the name of a configuration without selecting it. In this example, collatzplot_new_largevalue is selected and you can edit its expression or name. The pointer is positioned on collatzplot_new_2 and you can see the statements in it.

    Image of Edit Configurations dialog box with three run configurations listed in the left pane. The cursor is over one of the run configuration names and the tooltip is open. The tooltip displays the MATLAB Expression for the configuration that the cursor is hovering over.

  5. To close the Edit Configurations dialog box, click Close. MATLAB saves the configurations and their associations with the file in run_configurations.m in your preferences folder.

    For more information, see About the run_configurations.m File.

About the run_configurations.m File

When you create one or more run configurations using the Edit Configurations dialog box, the Editor creates or updates the run_configurations.m file in your preferences folder. (MATLAB returns the preferences folder when you run prefdir.) The run_configurations.m file is a text file that you can view and use to evaluate MATLAB code files.

Although you can port this file from the preferences folder on one system to another, there can only be one run_configurations.m file on a system. Therefore, only do this if you have not already created configurations on the second system. Also, because this file might contain references to file paths, ensure that the MATLAB file and paths it specifies exist on the second system.

MathWorks recommends that you do not update this file in the Editor or a text editor. Changes you make using tools other than the Edit Configurations dialog box might be overwritten.

Each time you change a run configuration using the Edit Configurations dialog box, MATLAB updates the run_configurations.m file as well as the publish_configurations.m file. See About the publish_configurations.m File for more information about that file.

Find Configurations

Follow these steps to find run or publish configurations. (For information on publish configurations, see Specifying Output Preferences for Publishing.)

  1. Open any MATLAB code file in the Editor.

  2. In the Editor toolbar, click the down arrow on the Run button , and then select Edit Run Configurations for any file name.

  3. In the Edit Configurations dialog box, click the Clear search button within the filter field Image of Clear search button to clear the filter field.

    In the left pane, MATLAB lists all files with configurations.

    Image of Edit Configurations dialog box listing multiple configurations.

  4. Type a term in the filter field Image of the filter field from the Edit Configurations dialog box. to find a file or configuration by name.

    MATLAB displays only those files whose names contain the term, or whose associated configurations contain the term in their name. As you type, MATLAB filters out files any configurations that do not contain the term.

    For example, type rand. In this example, only one file, collatzplot_new.m, has a configuration that contains the term rand.

    Image of Edit Configurations dialog box with collatzplot_new_random... displaying in the left pane.

  5. View the expression in that configuration by positioning the mouse pointer over the name.

  6. As you type additional letters in the filter field, fewer files remain in the list of results. Use the Backspace key to modify the term. If there are no files or configurations containing the term, the list is empty.

Remove Configurations

If you no longer need a run or publish configuration because you do not use it or because you deleted the file with which it is associated, consider deleting the configuration. (For information on publish configurations, see Specifying Output Preferences for Publishing.)

  1. Open any MATLAB code file in the Editor.

  2. In the Editor toolbar, click the down arrow on the Run button , and then select Edit Run Configurations for any file name.

  3. In the Edit Configurations dialog box, click the Clear search button within the filter field Image of Clear search button to clear the filter field.

  4. In the Edit Configurations dialog box, do one of the following in the pane on the left:

    • To remove a single configuration, select that configuration.

    • To remove all the run and publish configurations for the file, select the file.

  5. Click the Remove button .

  6. To undo the last deletion, click the Undo button . You cannot undo the last deletion after you close this dialog box.

Reassociate and Rename Configurations

Each run and publish configuration is associated with a specific file. If you move or rename a file that has configurations, redefine the association. If you delete a file, consider deleting the associated configurations, or associate them with a different file.

When MATLAB cannot associate a configuration with a file, the Edit Configurations dialog box displays the file name in red, displays a File Not Found message, and enables you to find the file to which you want to associate the configuration.

To reassociate a configuration:

  1. In the Editor toolbar, click the down arrow on the Run button , and then select Edit Run Configurations for any file name.

  2. In the Edit Configurations dialog box, click the Clear search button within the filter field Image of Clear search button to clear the filter field.

  3. In the left pane, select the file for which you want to reassociate configurations, and then click Choose.

  4. In the resulting Open dialog box, navigate to and select the file with which you now want to reassociate the configurations. Click Open.

    In the Edit Configurations dialog box, the Associated file value reflects the change you made and the File Not Found message no longer appears.

  5. Rename the configurations to be consistent with the new file name

    Select a configuration from the list in the left pane. In the right pane, edit the value for the configuration name. Repeat this step for all run and publish configurations associated with the file.

  6. For a file name change, you might need to modify the configuration statements to run correctly. For example, change a function call to reflect the new file name for that function.

  


Recommended Products

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

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