%% 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 the script.

run(newFile)

% Copyright 2012 The MathWorks, Inc.