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 accepts explicit figure numbers, figure-number arrays, and RunMat's 'all' selector. Typed integer figure numbers are an exact structural convenience available in RunMat mode; compatibility mode accepts ordinary double figure numbers.
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')is a separately gated RunMat convenience that clears every known figure and returns the number of figures that were cleared; compatibility mode rejects it before plotting-state access.clf(handle1, handle2, ...)is a separately gated RunMat convenience that clears multiple figures and returns the number cleared. Compatibility syntax uses one figure object or figure array.clf('reset')is currently treated the same as plainclf.- In RunMat mode, scalar and array figure numbers can use any of the eight integer classes. Values are read from authoritative integer storage and must be positive and no larger than
uint32's maximum. - Typed integer figure numbers are rejected in compatibility mode because the public compatibility contract documents figure numbers but does not advertise integer classes. GPU-resident numeric targets are rejected without provider dispatch.
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 host plotting state. Figure-number controls must be host values; resident numeric targets are rejected without gathering.
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.
Can figure numbers use integer classes?⌄
Yes in RunMat mode. int8, int16, int32, int64, uint8, uint16, uint32, and uint64 are exact structural selectors, subject to the positive uint32 figure-number range. Compatibility mode requires an ordinary double figure number.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · caxis · cla · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · text · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
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.