pause — Suspend execution until user interaction or for a duration.
pause supports keypress wait, nonnegative scalar duration, and session-owned on/off/query state control.
Syntax
out = pause()
out = pause(duration)
state = pause(command)Inputs
duration- Type
Any- Required
- Yes
- Description
- Nonnegative scalar duration in seconds, or an empty value for keypress wait.
command- Type
StringScalar- Required
- Yes
- Description
- One of 'on', 'off', or 'query'.
Returns
out- Type
NumericArray- Description
- Empty array when waiting.
state- Type
StringScalar- Description
- Previous or current pause state, 'on' or 'off'.
Errors
RunMat:pause:InvalidInputArgument- When
- Input is malformed, unsupported, nonscalar, or a negative/non-finite duration.
- Message
pause: invalid input argument
RunMat:pause:TooManyInputs- When
- More than one input argument is supplied.
- Message
pause: too many input arguments
RunMat:pause:GpuGatherFailed- When
- Gathering a resident input through its owner fails.
- Message
pause: failed to gather gpu input
RunMat:pause:ContextUnavailable- When
- No invocation timing context is installed.
- Message
pause: runtime context is unavailable
Behavior and placement
pause and pause([]) wait for a keypress when enabled; noninteractive standard input may complete immediately. Positive-infinite numeric input follows the default keypress form.
pause(n) waits for a nonnegative real scalar duration in seconds. Zero provides an asynchronous yield point. Waiting is cooperative and cancellation stops the pending timer.
pause('off') and pause('on') change the current session's policy and return the previous state as a character row; pause('query') reads the current state without changing it. Each new runtime context begins enabled.
Every built-in integer scalar class is accepted from authoritative storage before converting at the host timer boundary; logical scalars are also accepted.
Explicit gpuArray input is a RunMat-mode extension gated before provider access. Automatically resident input is gathered through its owner; no pause operation runs on the GPU or joins fusion.
Examples
Pausing for a fixed duration
tic;
pause(0.05);
elapsed = tocWaiting for user input mid-script
disp('Press any key to continue the demo...');
pause;Temporarily disabling pauses in automated runs
previous = pause('off');
pause(1.0);
pause(previous);Querying the current pause mode
current = pause('query');Using empty input to rely on the default behaviour
pause([]);Using pause with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how pause changes the result.
Run a small pause example, explain the result, then change one input and compare the output.
FAQ
Does pause block forever when standard input is not interactive?⌄
No. A noninteractive host may complete a keypress request immediately; interactive hosts wait for a key.
What happens if I call pause with a negative duration?⌄
RunMat raises RunMat:pause:InvalidInputArgument.
Does pause accept logical or integer values?⌄
Yes. Logical scalars and all eight integer classes are accepted; integer storage is read exactly before the host timer conversion.
Can I force pausing off globally?⌄
pause('off') disables waits in the current session. Save the returned state and pass it to pause to restore it.
Does pause('query') change the pause state?⌄
No. It returns the current mode, 'on' or 'off'.
Is pause affected by GPU fusion or auto-offload?⌄
It does not enter a GPU timing kernel or fusion; automatically resident input may require owner-aware gather.
What is the default pause state?⌄
'on' for every new RunMat session.
Can I pass a gpuArray as the duration?⌄
RunMat mode accepts explicit gpuArray duration as a gated extension and gathers through the owning provider.
Related Timing functions
cputime · set.BusyMode · set.ErrorFcn · set.ExecutionMode · set.Name · set.ObjectVisibility · set.Period · set.StartDelay · set.StartFcn · set.StopFcn · set.Tag · set.TasksToExecute · set.TimerFcn · set.UserData · tic · timeit · timer · timerfind · timerfindall · toc
Source you can read
Every RunMat function's source is public. Read exactly how pause is executed, line by line, in Rust.
- View the source for pause in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.