This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Wait for job to change state


OK = wait(j,state,timeout)



Job object whose change in state to wait for.


Value of the job object’s State property to wait for.


Maximum time to wait, in seconds.


wait(j) blocks execution in the client session until the job identified by the object j reaches the 'finished' state or fails. This occurs when all the job’s tasks are finished processing on the workers.

wait(j,state) blocks execution in the client session until the specified job object changes state to the value of state. The valid states to wait for are 'queued', 'running', and 'finished'.

If the object is currently or has already been in the specified state, a wait is not performed and execution returns immediately. For example, if you execute wait(j,'queued') for a job already in the 'finished' state, the call returns immediately.

OK = wait(j,state,timeout) blocks execution until either the job reaches the specified state, or timeout seconds elapse, whichever happens first. OK is false if timeout is exceeded before state is reached.


Simulink® models cannot run while a MATLAB® session is blocked by wait. If you must run Simulink from the MATLAB client while also running jobs, you cannot use wait.


Submit a job to the queue, and wait for it to finish running before retrieving its results.

results = fetchOutputs(j)

Submit a batch job and wait for it to finish before retrieving its variables.

j = batch('myScript');

Introduced in R2008a