Quantcast

Documentation Center

  • Trial Software
  • Product Updates

run

Run MATLAB script

Syntax

Description

example

run(scriptname) runs the MATLAB® script specified by scriptname.

Examples

expand all

Run Script Not on Current Path

Create a temporary folder and copy an example MATLAB script to it.

tmp = tempname;
mkdir(tmp);
runtmp = fullfile(tmp,'buckyball.m');
demodir = fullfile(matlabroot,'toolbox','matlab',...
    'demos','buckydem.m');
copyfile(demodir,runtmp);

Run the new script.

run(runtmp)

Input Arguments

expand all

scriptname — Full or relative script pathstring

Full or relative script path to a MATLAB script, specified as a string. scriptname can specify any file type that MATLAB can execute, such as MATLAB script files, Simulink models, or MEX-files.

More About

expand all

Tips

  • run executes scripts not currently on the MATLAB path. However, you should use cd or addpath to navigate to or to add the appropriate folder, making a script executable by entering its name alone.

  • scriptname can access any variables in the current workspace.

  • run changes to the folder that contains the script, executes it, and resets back to the original folder. If the script itself changes folders, then run does not revert to the original folder, unless scriptname changes to the folder in which this script resides.

  • If scriptname corresponds to both a .m file and a P-file residing in the same folder, then run executes the P-file. This occurs even if you specify scriptname with a .m extension.

  • If a script is not on the MATLAB path, executing the run command caches the script. In the same session and after calling run, you can edit the script using an external editor. Call clear scriptname before calling run again to use the changed version of the script rather than the cached version. If you edit the script with the MATLAB editor, run executes the changed version and there is no need to call clear scriptname.

See Also

| | |

Was this topic helpful?