Stop MATLAB execution temporarily - MATLAB pause (2024)

Stop MATLAB execution temporarily

collapse all in page

Syntax

pause

pause(n)

pause(state)

oldState = pause(state)

Description

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.

example

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

example

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

example

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.

Examples

collapse all

Pause Execution

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

n = 5;pause(n)

Disable Pause Setting

Open Live Script

Disable the pause setting and query the current state.

pause('off')pause('query')
ans = 'off'

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

pause(100)

Enable the pause setting.

pause('on')

Save and Restore Pause State

Open Live Script

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

oldState = pause('off')
oldState = 'on'

Query the current pause setting.

pause('query')
ans = 'off'

Restore the initial pause state.

pause(oldState)pause('query')
ans = 'on'

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

oldState = pause('query');pause('off')

Restore the initial pause state.

pause(oldState)

Input Arguments

collapse all

nNumber of seconds
nonnegative, 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

statePause 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.

Tips

  • 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

    • Callbacks from figure windows

    • Event handling from Java windows

Extended Capabilities

Version History

Introduced before R2006a

See Also

keyboard | input | drawnow

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Stop MATLAB execution temporarily - MATLAB pause (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Stop MATLAB execution temporarily - MATLAB pause (2024)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 6370

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.