clearvars
clearvars variable_name_1 ... variable_name_N
clearvars('-except', keep_variable_1, ..., keep_variable_N)
clearvars(variable_name_1, ..., variable_name_N, '-except', keep_variable_1, ..., keep_variable_N)
clearvars('-regexp', expression_1, ..., expression_N)
clearvars(..., '-except', '-regexp', keep_expression_1, ..., keep_expression_N)
clearvars('-global', ...)
| Parameter | Description |
|---|---|
| variable_name | a character vector or string scalar: variable name or wildcard pattern using *. |
| keep_variable | a character vector or string scalar: variable name or wildcard pattern to preserve. |
| -regexp | selects variables whose names match one of the regular expressions. |
| -except | keeps matching variables and removes the other selected variables. |
| -global | removes matching global variables. This option must be the first argument. |
clearvars removes variables from the current workspace. Without input arguments, it removes all variables in the current workspace.
Named variables can be passed in command form or function form. Option arguments are passed in function form.
Wildcard patterns use * to match any sequence of characters. Regular expressions are enabled with -regexp.
When a variable is global, clearvars without -global removes it from the current workspace only. With -global, matching global variables are removed from the global workspace.
a = 1;
b = 2;
c = 3;
clearvars a c
who
A = 1;
B = 2;
C = 3;
clearvars('-except', 'A', 'C')
who
alpha = 1;
angle = 2;
beta = 3;
clearvars('a*', '-except', 'angle')
who
MonValue = 1;
TueValue = 2;
KeepValue = 3;
clearvars('-regexp', '^(Mon|Tue)')
who
global gx gy
gx = 1;
gy = 2;
clearvars('-global', '-except', 'gx')
isglobal('gx')
isglobal('gy')
clear global gx gy
| Version | Description |
|---|---|
| 2.0.0 | initial version |