2

is there a way to run a matlab script on the command line and make matlab block until the script is done?

I can invoke a single execution of the script on the command line like so:

"C:\Program Files\MATLAB\R2017a\bin\matlab.exe" -nodisplay -nosplash -nodesktop -r "run('C:\Users\myuser\profile.m');exit;"

There have been several questions on running a script in matlab in command line mode but all of them are about just invoking a single execution via cmd.

They aren't tackling the issue of executing the script multiple times sequentially or executing several scripts in order where one has to finish before the other one is started.

Matlab: Running an m-file from command-line

Open a GUI directly from desktop (Shortcut) in MATLAB environment

If I created a batch file with N repetition of the above command, they will all be started at the same time. Since I'm profiling a set of commands, I'd like them to run on their own. I could also create a script which repeats the current script N times and call this from matlab but I'd rather have matlab process shutdown between invocations so that persistent variables are cleared.

s5s
  • 11,159
  • 21
  • 74
  • 121

1 Answers1

2

You can use the -wait option above like so:

"C:\Program Files\MATLAB\R2017a\bin\matlab.exe" -wait -nodisplay -nosplash -nodesktop -r "run('C:\Users\myuser\profile.m');exit;"
s5s
  • 11,159
  • 21
  • 74
  • 121