Как остановить программу в матлаб
Перейти к содержимому

Как остановить программу в матлаб

  • автор:

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.

Examples

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

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

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

n — Number 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

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.

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

  • The use of pause in parfor loops is not supported for MEX code generation.
  • The generated code truncates pause delay values to uint32 range during run-time execution.
  • In generated standalone ( lib , dll , or exe ) code, the pause syntax with no input arguments has different behavior than in MATLAB.
  • In MATLAB, after pause execution you can press any key to continue. When running generated code from the terminal, you must press enter.
  • If you call the generated code from MATLAB with the system command or exclamation point character, with SIL, or with PIL, input characters may not be correctly redirected from the MATLAB environment to the generated code. Therefore the generated code might not resume.
  • When generating code on Windows ® with Windows-compatible hardware settings, the generated C/C++ implementation uses the Windows API function Sleep .
  • In all other cases, the implementation uses the POSIX API nanosleep . When compiling code that uses the POSIX API, the preprocessor macro _POSIX_C_SOURCE must be set to an integer greater than or equal to 199309L . The code generator sets the macro to 199309L for compilation.

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool .

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced before R2006a

Как остановить программу в матлаб

To stop execution of a MATLAB ® command, press Ctrl+C or Ctrl+Break.

On Apple Macintosh platforms, you also can use Command+. (the Command key and the period key).

Ctrl+C does not always stop execution for files that run a long time, or that call built-ins or MEX-files that run a long time. If you experience this problem, include a drawnow , pause , or getframe function in your file, for example, within a large loop. Also, Ctrl+C might be less responsive if you start MATLAB with the -nodesktop option.

Note

For certain operations, stopping the program might generate errors in the Command Window.

To programmatically stop execution of a function or script before reaching the end, use the return function. MATLAB returns control to the Command Window or the invoking function.

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.

Examples

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

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

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

n — Number 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

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.

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

  • The use of pause in parfor loops is not supported for MEX code generation.
  • The generated code truncates pause delay values to uint32 range during run-time execution.
  • In generated standalone ( lib , dll , or exe ) code, the pause syntax with no input arguments has different behavior than in MATLAB.
  • In MATLAB, after pause execution you can press any key to continue. When running generated code from the terminal, you must press enter.
  • If you call the generated code from MATLAB with the system command or exclamation point character, with SIL, or with PIL, input characters may not be correctly redirected from the MATLAB environment to the generated code. Therefore the generated code might not resume.
  • When generating code on Windows ® with Windows-compatible hardware settings, the generated C/C++ implementation uses the Windows API function Sleep .
  • In all other cases, the implementation uses the POSIX API nanosleep . When compiling code that uses the POSIX API, the preprocessor macro _POSIX_C_SOURCE must be set to an integer greater than or equal to 199309L . The code generator sets the macro to 199309L for compilation.

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool .

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced before R2006a

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.

Examples

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

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

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

n — Number 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

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.

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

  • The use of pause in parfor loops is not supported for MEX code generation.
  • The generated code truncates pause delay values to uint32 range during run-time execution.
  • In generated standalone ( lib , dll , or exe ) code, the pause syntax with no input arguments has different behavior than in MATLAB.
  • In MATLAB, after pause execution you can press any key to continue. When running generated code from the terminal, you must press enter.
  • If you call the generated code from MATLAB with the system command or exclamation point character, with SIL, or with PIL, input characters may not be correctly redirected from the MATLAB environment to the generated code. Therefore the generated code might not resume.
  • When generating code on Windows ® with Windows-compatible hardware settings, the generated C/C++ implementation uses the Windows API function Sleep .
  • In all other cases, the implementation uses the POSIX API nanosleep . When compiling code that uses the POSIX API, the preprocessor macro _POSIX_C_SOURCE must be set to an integer greater than or equal to 199309L . The code generator sets the macro to 199309L for compilation.

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool .

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced before R2006a

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *