MATLAB Language Multithreading Using the batch command to do various computations in parallel


To use multi-threading in MATLAB one can use the batch command. Note that you must have the Parallel Computing toolbox installed.

For a time-consuming script, for example,

for ii=1:1e8

to run it in batch mode one would use the following:


which is enables MATLAB to run in batch mode and makes it possible to use MATLAB in the meantime to do other things, such as add more batch processes.

To retrieve the results after finishing the job and load the array A into the workspace:

load(job, 'A')

Finally, open the "monitor job gui" from HomeEnvironmentParallelMonitor jobs and delete the job through:


To load a function for batch processing, simply use this statement where fcn is the function name, N is number of output arrays and x1, ..., xn are input arrays:

 j=batch(fcn, N, {x1, x2, ..., xn})