Run MATLAB script
run( scriptname ) runs the MATLAB ® script specified by scriptname .
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)
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")
Introduced before R2006a