clear — Clear variables from the active workspace.
clear removes variables from the active RunMat workspace. RunMat supports MATLAB-style clear, clear all, and named-variable forms such as clear x or clear x y, updating the session snapshot so removed variables disappear from subsequent workspace queries.
How clear works
clearwith no inputs clears all workspace variables created in the current session.clear('all')and command-formclear allare treated the same as bareclear.clear xremoves the variablexwhile leaving other workspace bindings intact.- Multiple names can be supplied as separate inputs or command-form tokens, for example
clear x y z. - After a successful clear, removed variables are no longer available to later statements and the workspace snapshot is refreshed so hosts can drop cleared bindings.
- Accepts variable names as string scalars, row character vectors, or string arrays. If any input is
all, the entire workspace is cleared. - Clearing a name that does not exist is a no-op.
clearis a sink builtin and does not produce a meaningful output value.
How RunMat runs clear on the GPU
clear performs host-side workspace mutation only. It does not launch GPU kernels, does not participate in fusion, and does not depend on acceleration providers.
Examples
Clear the entire interactive workspace
x = 1;
y = magic(3);
clearExpected output:
% x and y are removed from the workspaceUse MATLAB-style command form
a = 42;
clear allExpected output:
% a is removed from the workspaceAccessing a cleared variable raises an error
x = 7;
clear;
xExpected output:
Undefined variable: xClear one variable while leaving others intact
x = 1;
y = 2;
clear xExpected output:
% x is removed from the workspace while y remains definedClear multiple named variables in command form
a = 1;
b = 2;
c = 3;
clear a bExpected output:
% a and b are removed; c remains definedFAQ
Does clear remove every variable in the current session?⌄
Bare clear and clear all clear the full workspace. Named forms such as clear x remove only the specified bindings.
Can I clear only one variable?⌄
Yes. Use clear x or clear("x") to remove one variable, and pass multiple names to clear more than one binding in a single call.
Does clear return anything?⌄
No meaningful value is returned. clear is a side-effecting builtin whose purpose is to mutate workspace state.
Does clear affect plotting state or the console?⌄
No. clear only clears workspace variables. Use plotting commands such as close all for figures and clc for the visible console.
Does GPU residency matter?⌄
No. clear operates on session bookkeeping, not on array kernels or provider-managed computations.
Related Introspection functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how clear works, line by line, in Rust.
- View clear.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.