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
    • addprop
    • assignin
    • class
    • clear
    • clearAllMemoizedCaches
    • clearCache
    • clearvars
    • dbclear
    • dbstack
    • dbstatus
    • dbtype
    • evalc
    • feval
    • findprop
    • getcallinfo
    • inputParser
    • isa
    • ischar
    • isdeployed
    • iskeyword
    • ismethod
    • isobject
    • isstring
    • isUnderlyingType
    • keyboard
    • matlab.metadata.DynamicProperty.delete
    • memoize
    • metaclass
    • mislocked
    • mlock
    • munlock
    • namelengthmax
    • narginchk
    • nargoutchk
    • notify
    • onCleanup
    • stats
    • str2func
    • superclasses
    • underlyingType
    • verLessThan
    • version
    • which
    • who
    • whos

clearvars — Clear workspace variables with optional exclusions in MATLAB and RunMat.

clearvars removes variables from the active workspace, with optional -except exclusions. Named and exclusion forms follow MATLAB semantics for selectively clearing bindings.

Syntax

clearvars()
clearvars(name_or_option, ...)

Inputs

NameTypeRequiredDefaultDescription
name_or_optionStringScalarVariadic—Variable names and options such as '-except'.

Returns

NameTypeDescription
ansNumericArrayEmpty 0x0 return value.

Errors

IdentifierWhenMessage
—The '-except' option appears more than once.clearvars: duplicate -except option
—An unknown option beginning with '-' is provided.clearvars: unsupported option
—The '-except' option is provided without exclusion names.clearvars: -except requires at least one variable name
—Workspace snapshot is unavailable while processing '-except'.clearvars: workspace state unavailable
—Character-array argument is not a row vector.clearvars: character array inputs must be a row vector or scalar text value
—An argument is not a string scalar/array or row character vector.clearvars: expected variable names as character vectors or string scalars

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.
  • Active onCleanup objects are invoked before removed workspace bindings are deleted; excluded cleanup objects remain active.
  • 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.

Does RunMat run 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

Using clearvars with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how clearvars changes the result.

Run a small clearvars example, explain the result, then change one input and compare the output.

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.

Related Introspection functions

addprop · assignin · class · clear · clearAllMemoizedCaches · clearCache · dbclear · dbstack · dbstatus · dbtype · evalc · feval · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · notify · onCleanup · stats · str2func · superclasses · underlyingType · verLessThan · version · which · who · whos

Open-source implementation

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

  • View the source for clearvars 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 clearvars works
  • Does RunMat run clearvars on the GPU?
  • Examples
  • Clear the entire interactive workspace
  • Clear selected variables
  • Keep selected variables while clearing the rest
  • Clear selected variables while preserving exclusions
  • Using clearvars with coding agents
  • FAQ
  • Related Introspection functions
  • Open-source implementation
  • About RunMat