RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • binscatter
    • close
    • qqplot
    • scatterhist

close — Close figures or networking resources in MATLAB and RunMat.

close releases plotting figures and TCP clients/servers. Bare close targets the current figure and is a no-op when no figures exist, so common startup code such as clc; clear; close is safe. In RunMat mode, typed integer figure numbers are exact structural selectors; compatibility mode accepts ordinary double figure numbers.

Syntax

result = close()
result = close(target)
result = close(targets...)

Inputs

NameTypeRequiredDefaultDescription
targetAnyYes—Figure target, tcp resource handle, option token, or target container.
targetsAnyVariadic—One or more close targets.

Returns

NameTypeDescription
resultNumericScalarScalar double status: 1 when the requested close operation completes, 0 when it is refused.

Errors

IdentifierWhenMessage
RunMat:close:InvalidArgumentClose target values are invalid or unsupported.close: invalid argument
RunMat:close:InvalidHandleA structure target is not a valid networking resource handle.close: invalid handle
—Internal networking, gather, or plotting close processing fails.close: internal error

How close works

  • close with no arguments closes the current figure when one exists. If no figure exists, it is a successful no-op that returns 1 without creating a default figure.
  • close('all') closes every open figure. Networking resources use explicit selectors such as close('clients') and close('servers').
  • close(fig) closes an explicit figure handle and raises a figure-handle diagnostic if that explicit handle does not exist.
  • close(t) closes the TCP client struct t that was previously returned by tcpclient or accept. Subsequent socket operations on that client raise MATLAB-style “not connected” diagnostics.
  • close(s) closes the TCP server struct s that was returned by tcpserver. Any clients that were accepted from that server are also disconnected to match MATLAB’s lifecycle rules.
  • close('clients') closes every registered TCP client (including those produced by accept). Likewise, close('servers') closes every TCP server. Use those explicit networking selectors instead of close('all'), which is reserved for figure closure.
  • Plotting forms return scalar double 1 after a successful or no-op close. A 0 status is reserved for refused closure, which RunMat cannot yet produce because CloseRequestFcn callbacks are not implemented. Networking inputs return 1 when at least one resource was closed and 0 otherwise.
  • Invalid arguments raise RunMat:close:InvalidArgument. Structs that do not contain the hidden RunMat networking identifiers raise RunMat:close:InvalidHandle.
  • Networking happens on the CPU. Resident numeric arguments are not networking resources and are rejected as non-host figure targets before provider dispatch.
  • In RunMat mode, networking resources may be passed as separate arguments or wrapped in nested cell arrays, and networking selectors may be scalar strings. Separate variadic targets are rejected in compatibility mode; plotting figure targets are not accepted through cell containers in the current implementation.
  • In RunMat mode, scalar and array figure numbers can use any of the eight integer classes. Values are read exactly, must be positive, and must fit RunMat's uint32 figure-number range. Compatibility mode rejects typed integer figure numbers because the public compatibility contract does not advertise integer classes.

Does RunMat run close on the GPU?

close performs only CPU-side bookkeeping. Resident numeric values cannot be networking resources and bypass the networking gather path; plotting then rejects them as non-host figure targets without provider dispatch.

Examples

Start a script safely when no figures are open

clc;
clear;
status = close

Expected output:

status = 1

Close the current figure

figure(7);
status = close

Expected output:

status = 1

Close a TCP client after finishing I/O

client = tcpclient("127.0.0.1", 50000);
status = close(client)

Expected output:

status = 1

Close a TCP server and any accepted clients

srv = tcpserver("127.0.0.1", 0);
client = accept(srv);             % accept a pending connection
status = close(srv);              % closes the server and the accepted client

Expected output:

status = 1

Close every open TCP client

tcpclient("localhost", 40000);
tcpclient("localhost", 40001);
status = close("clients")

Expected output:

status = 1

Close networking resources by selector

client = tcpclient("localhost", 40000);
srv = tcpserver("localhost", 0);
clientStatus = close("clients");
serverStatus = close("servers")

Expected output:

clientStatus = 1
serverStatus = 1

Calling close on an already-closed client

client = tcpclient("127.0.0.1", 50000);
close(client);
status = close(client);   % nothing left to close

Expected output:

status = 0

Close handles stored in a cell array

client = tcpclient("localhost", 40000);
srv = tcpserver("localhost", 0);
handles = {client, srv};
status = close(handles)

Expected output:

status = 1

Using 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

Is bare close safe when no figures are open?⌄

Yes. RunMat treats bare close as a successful no-op when there is no current figure, returning 1 without creating a default figure or raising an invalid-handle error.

What does the return value represent?⌄

Figure forms return scalar double 1 when the requested operation succeeds or has nothing to close. MATLAB can return 0 when a close callback refuses the request; RunMat does not yet implement that callback path. Networking resources return 1 when at least one client or server was closed and 0 otherwise.

Can I pass multiple clients or servers at once?⌄

Yes in RunMat mode. Pass them as separate arguments (close(client1, client2)) or wrap them in a cell array. Separate variadic targets are a RunMat extension; compatibility mode accepts one target argument.

Does closing a server also close accepted clients?⌄

Yes. RunMat mirrors MATLAB by closing every client that originated from the server before releasing the listener itself.

What happens if I pass a non-network struct?⌄

The builtin raises RunMat:close:InvalidHandle. Only structs produced by the RunMat networking builtins (tcpclient, tcpserver, accept) carry the hidden identifiers that close recognises.

Do GPU arrays require special handling?⌄

Resident numeric values are not networking resources and are rejected as non-host figure targets before provider access. Networking structs and plotting state remain host-resident.

Is it safe to call close twice?⌄

It depends on the target. Repeating an explicit figure-number close raises the missing-handle diagnostic, while bare close with no current figure is a successful no-op returning 1. Repeating a networking close returns 0 when no resource remained to close.

Can figure numbers use integer classes?⌄

Yes in RunMat mode. All eight signed and unsigned integer classes are accepted exactly as host structural selectors within the positive uint32 range. Compatibility mode requires an ordinary double figure number.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. 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 an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How close works
  • Does RunMat run close on the GPU?
  • Examples
  • Start a script safely when no figures are open
  • Close the current figure
  • Close a TCP client after finishing I/O
  • Close a TCP server and any accepted clients
  • Close every open TCP client
  • Close networking resources by selector
  • Calling close on an already-closed client
  • Close handles stored in a cell array
  • Using close with coding agents
  • FAQ
  • Open-source implementation
  • About RunMat