RunMat
GitHub

clearvars — Clear variables from the active workspace, with optional exclusions.

clearvars removes variables from the active RunMat workspace. RunMat supports MATLAB-style command forms such as clearvars x y, whole-workspace exclusion forms such as clearvars -except keep, and selected-variable exclusion forms such as clearvars a b -except b, updating the session snapshot so hosts can drop cleared bindings.

How clearvars works

  • clearvars with no inputs clears all workspace variables created in the current session.
  • clearvars x removes the variable x while leaving other workspace bindings intact.
  • Multiple names can be supplied as separate inputs or command-form tokens, for example clearvars x y z.
  • clearvars -except x y removes all active workspace variables except x and y.
  • clearvars a b c -except b removes only selected variables a and c, preserves selected exclusion b, and leaves variables outside the selected clear set untouched.
  • Function-call forms accept variable names as string scalars, row character vectors, or string arrays.
  • Clearing a name that does not exist is a no-op.
  • clearvars is a sink builtin and does not produce a meaningful output value.

How RunMat runs clearvars on the GPU

clearvars 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);
clearvars

Expected output:

% x and y are removed from the workspace

Clear selected variables

a = 1;
b = 2;
c = 3;
clearvars a b

Expected output:

% a and b are removed; c remains defined

Keep selected variables while clearing the rest

raw = 1;
answer = 42;
tmp = 3;
clearvars -except answer

Expected output:

% answer remains defined; raw and tmp are removed

Clear selected variables while preserving exclusions

a = 1;
b = 2;
c = 3;
untouched = 4;
clearvars a b c -except b

Expected output:

% a and c are removed; b and untouched remain defined

FAQ

How is clearvars different from clear?

clearvars focuses on workspace variables and supports the -except option for preserving named bindings while clearing the rest.

Can I clear only one variable?

Yes. Use clearvars x or clearvars("x") to remove one variable, and pass multiple names to clear more than one binding in a single call.

Does clearvars -except x clear figures or the console?

No. It only mutates workspace variables. Use close all for figures and clc for the visible console.

Does GPU residency matter?

No. clearvars operates on session bookkeeping, not on array kernels or provider-managed computations.

class · clear · isa · ischar · isstring · which · who · whos

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how clearvars works, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Try RunMat for free

Open the sandbox and start running MATLAB code in seconds. No account required.