Run matlab file without terminal output

Run MATLAB script

Syntax

Description

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

Examples

Run Script Not on Current Path

Create a temporary folder that is not on your current path.

tmp = tempname; mkdir(tmp)

Write MATLAB code to a file in the folder.

newFile = fullfile(tmp,'ANewFile.m'); fid = fopen(newFile,'w'); fprintf(fid,'Z = magic(5);\n'); fprintf(fid,'b = bar3(Z);\n'); fclose(fid);
run(newFile)

Figure contains an axes object. <a href=The axes object contains 5 objects of type surface." width="583" />

Input Arguments

scriptname — Name of MATLAB script
string scalar | character vector

Name of MATLAB script, specified as a string scalar or character vector. scriptname can be any file type that MATLAB can execute, such as a MATLAB script file, Simulink ® model, or MEX-file. scriptname can access any variables in the current workspace.

If scriptname is in the current folder or in a folder on the MATLAB path, specify just the name of the file.

If scriptname is not in the current folder or in a folder on the MATLAB path, specify the full or relative path of the file. Alternatively, you can use cd to change the current folder to the folder that contains the file, or use addpath to add the containing folder to the MATLAB path. Then, you can specify just the name of the file.

Note

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.

Example: run("myScript")

Example: run("anotherScript.mlx")

Example: run("C:\myFolder\myScript.m")

Example: run("myFolder\anotherScript.mlx")

Tips

Version History

Introduced before R2006a