Skip to content

Blocking the Matlab command line

Brian Lau edited this page Feb 23, 2014 · 2 revisions

By default, optimization and sampling do not block the Matlab command line. These processes are run in the background so you can keep working while Stan chugs away. This can occasionally cause problems. For example, a script that fits a Stan model and then runs a series of commands processing MCMC samples will fail as these commands will be executed before sampling is finished. There are two ways to get around this. One is to use the block() method for StanFit objects, which will block the command line until sampling is finished:

fit = stan('model_code',code,'data',data);
fit.block();

The second method is to use listeners to notify when sampling is complete.