close — Close figures or a session-owned TCP resource.
Bare close closes the current figure and succeeds when none exists. close('all') closes figures. A sealed TCP client or server, or the RunMat selectors 'clients' and 'servers', closes only resources owned by the installed TCP service.
Syntax
close
status = close()
status = close(target)
status = close(targets...)Inputs
target- Type
Any- Required
- Yes
- Description
- Figure number, sealed TCP receiver, or an admitted close selector.
targets- Type
Any- Required
- Variadic
- Description
- RunMat-only separate close targets.
Returns
status- Type
NumericScalar- Description
- Scalar double: graphics completion, or whether a TCP resource was closed.
Errors
RunMat:close:TooManyOutputs- When
- More than one output is requested.
- Message
close: too many output arguments
RunMat:close:InvalidArgument- When
- A graphics target or TCP selector is invalid.
- Message
close: invalid argument
RunMat:close:InvalidHandle- When
- A TCP-looking receiver has no sealed socket authority.
- Message
close: invalid handle
Graphics forms
close, close(fig), and close('all') close the current, selected, or all figures. Successful and no-op graphics forms return scalar double 1. An explicit nonexistent figure raises its figure-handle diagnostic. CloseRequestFcn refusal is not implemented, so graphics status 0 is not currently produced.
RunMat mode additionally accepts exact host integer figure selectors and separate variadic targets. Numeric GPU targets are rejected before provider access. A cell of figure targets is not supported.
TCP forms
close(client) and close(server) use the receiver's sealed session authority. Closing a server also closes clients accepted from it. Closing an already-closed resource returns double 0; closing one or more live resources returns double 1.
close('clients') and close('servers') target the current session's TCP resources. Nested cells of TCP receivers are accepted in RunMat mode. The visible object class and properties are not socket authority; a forged or stale receiver cannot close another session's socket.
TCP closure requires the installed native TCP service. Browser TCP targets report the typed unsupported-target diagnostic after input admission; graphics close remains available in browser rendering. Cancellation is checked before and after each close. If cancellation or a later target fails after an earlier socket has closed, the call reports an error but that closure remains in effect; close does not replay or roll back earlier targets.
Additional workflows
A startup sequence such as clc; clear; close is safe with no open figures. For a loopback server, create s = tcpserver(...), accept a client, then close(s) to release both listener and accepted clients. Repeating close(s) returns 0.
RunMat networking selectors can close all clients or servers in a session. Use close('clients') and close('servers'), not close('all'): the latter belongs to graphics. A mixed figure/TCP target container is not admitted.
Examples
Close the current figure
figure(7);
assert(isgraphics(7));
status = close
assert(status == 1);
assert(~isgraphics(7));Expected output:
status = 1Close all figures
figure(8);
figure(9);
assert(isgraphics(8));
assert(isgraphics(9));
status = close('all')
assert(status == 1);
assert(~isgraphics(8));
assert(~isgraphics(9));Expected output:
status = 1Close a loopback TCP client
client = tcpclient('__RUNMAT_LOOPBACK_HOST__', __RUNMAT_LOOPBACK_PORT__);
write(client, uint8(9));
status = close(client)
assert(status == 1);
assert(close(client) == 0);Expected output:
status = 1Using close with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how close changes the result.
Run a small close example, explain the result, then change one input and compare the output.
FAQ
Can close be called twice?⌄
A repeated TCP close returns 0; a repeated explicit figure-number close raises the missing-figure diagnostic. Bare close with no current figure succeeds as a no-op.
Do GPU arrays require a kernel?⌄
No. Figure and TCP targets are host-managed. Resident numeric figure targets reject without a provider download.
Source you can read
Every RunMat function's source is public. Read exactly how close is executed, line by line, in Rust.
- View the source for close 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.