This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Stop MATLAB execution temporarily


  • pause


pause temporarily stops MATLAB® execution and waits for the user to press any key. The pause function also temporarily stops the execution of Simulink® models, but does not pause their repainting.

    Note:   If you previously disabled the pause setting, reenable it using pause('on') for this call to take effect.


pause(n) pauses execution for n seconds before continuing. Pausing must be enabled for this call to take effect.


pause(state) enables, disables, or displays the current pause setting.


oldState = pause(state) returns the current pause setting and sets the pause state as indicated by state. For example, if pausing is enabled, oldState = pause('off') returns 'on' in oldState and disables pausing.


collapse all

Pause Execution

Pause execution for 5 seconds. MATLAB blocks, or hides, the command prompt (>>) while it pauses execution.

n = 5;

Disable Pause Setting

Disable the pause setting and query the current state.

ans =


Pause execution for 100 seconds. Since the pause setting is off, MATLAB ignores the request to pause execution, and immediately returns the command prompt.


Enable the pause setting.


Save and Restore Pause State

Store the current pause setting and then disable the ability to pause execution.

oldState = pause('off')
oldState =


Query the current pause setting.

ans =


Restore the initial pause state.

ans =


Alternatively, you can store the queried value of the pause state and then disable the ability to pause execution.

oldState = pause('query');

Restore the initial pause state.


Input Arguments

collapse all

n — Number of secondsnonnegative, real number

Number of seconds to pause execution specified as a nonnegative, real number.

Typing pause(inf) puts you into an infinite loop. To return to the MATLAB prompt, type Ctrl+C.

Example: pause(3) pauses for 3 seconds.

Example: pause(5/1000) pauses for 5 milliseconds.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

state — Pause setting'on' | 'off' | 'query'

Pause control indicator specified as 'on', 'off', or 'query'. Use 'on' or 'off' to control whether the pause function is able to pause MATLAB execution. Use 'query' to query the current state of the pause setting.

To run interactive code unattended, disable the pause setting.

More About

collapse all


  • The accuracy of the pause function is subject to the scheduling resolution of your operating system, and to other concurrent system activity. The accuracy is not guaranteed, and finer resolution results in higher relative error.

  • While MATLAB is paused, the following continue to execute:

    • Repainting of figure windows, Simulink block diagrams, and Java® windows

    • HG callbacks from figure windows

    • Event handling from Java windows

See Also

| |

Introduced before R2006a

Was this topic helpful?