run

Runs a script file given by its path or name.

Category: Programming > Programming Utilities

Syntax

run(scriptname)

Runs the script in the current workspace.

Description

A script shares the workspace of the caller: variables it creates remain available, and it can read and change the caller's variables. run accepts a full or relative path, which the plain name form needs a folder on the search path for. The command form run name works as well.

Input arguments

scriptname
Name or path of the script file, with or without the .m extension.

Example

Writing and running a script

fid = fopen('demo_script.m', 'w');
fprintf(fid, 'msg = ''ran script'';\ndisp(msg)\n');
fclose(fid);
run('demo_script.m')
run demo_script
disp(msg)
delete('demo_script.m')
Output
ran script
ran script
ran script

See also

eval evalin feval exist addpath