clf — Clear figure contents in MATLAB and RunMat plotting.
clf clears the contents of the current figure while leaving the figure handle itself alive. It also accepts explicit figure handles and the 'all' selector, consistent with MATLAB and RunMat plotting behavior.
Syntax
result = clf()
result = clf(targets...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
targets | Any | Variadic | — | Figure handle(s) or mode tokens ('all', 'reset'). |
Returns
| Name | Type | Description |
|---|---|---|
result | NumericScalar | Cleared handle for single-target calls or count for multi/all clears. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:clf:InvalidArgument | One or more clear targets are invalid. | clf: invalid argument |
RunMat:clf:Internal | Internal figure clear operation fails. | clf: internal operation failed |
How clf works
clf()clears the current figure.clf(handle)clears the specified figure handle.clf('all')clears every known figure and returns the number of figures that were cleared.clf(handle1, handle2, ...)clears multiple figures and returns the number cleared when more than one handle is supplied.clf('reset')is currently treated the same as plainclf.
Does RunMat run clf on the GPU?
clf performs no provider dispatch; it clears figures from the plotting registry and renderer state.
GPU memory and residency
clf only mutates plotting state and does not affect array residency.
Examples
Clear the current figure after plotting
figure(1);
plot(1:5, [1 4 2 5 3]);
out = clf()Expected output:
% out is the cleared figure handleClear a specific figure by handle
figure(3);
plot(1:5, 1:5);
out = clf(3)Expected output:
out = 3Clear every figure
figure(1); plot(1:5, 1:5);
figure(2); plot(1:5, [5 4 3 2 1]);
count = clf("all")Expected output:
count = 2Using clf with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how clf changes the result.
Run a small clf example, explain the result, then change one input and compare the output.
FAQ
Does clf delete the figure handle itself?⌄
No. It clears the figure contents but keeps the figure handle selected and available.
What does clf('reset') do today?⌄
RunMat parses the keyword for compatibility, but the current implementation treats it the same as plain clf.
What does clf('all') return?⌄
It returns the number of figures that were cleared. When no figures exist, it returns 0.
Related Plotting functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how clf is executed, line by line, in Rust.
- View the source for clf 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.