clearvars
Delete all or specified variable(s) from memory in the current session of the application. When no variable names are specified, delete all variables. When -except is specified, exclude the specified variable names from deletion.
Syntax
clearvars
clearvarsx1, x2...
clearvars('-global')
clearvars -excepty1, y2...
Inputs
- x1, x2... (optional)
- If not specified, delete all variables. If names are specified, the variables with those names are deleted. Names can contain a wildcard '*' pattern in which case the variables with names that match the pattern are deleted.
- -global (optional)
- Argument that deletes global variables from memory, instead of local variables.
- -except y1, y2... (optional)
- Argument that excludes from deletion the variable names following this argument. Variable names can contain a wildcard '*' pattern, which excludes deletion of all variables with names that match the pattern.
Examples
global globalVariable;
testInteger = 24;
testString = 'This is a test string';
clearvars
who
Variables in current scope:
globalVariable
global globalVariable;
testInteger = 24;
testString = 'This is a test string';
clearvars('-global')
who
Variables in current scope:
testInteger
testString
global globalVariable;
testInteger = 24;
testString = 'This is a test string';
clearvars testInteger
who
Variables in current scope:
globalVariable
testString
global globalVariable;
testInteger = 24;
testString1 = 'This is string 1';
testString2 = 'This is an example for the command clearvars';
clearvars *ring*
who
Variables in current scope:
globalVariable
testInteger
global globalVariable;
testInteger = 24;
testString1 = 'This is string 1';
testString2 = 'This is an example for the command clearvars';
clearvars test* -except *g2
who
Variables in current scope:
globalVariable
testString2
Comments
If no arguments are passed, all variables are deleted from memory. If an optional argument, -global, is passed, only global variables are deleted from memory. If an optional argument x is passed, the variable associated with the name x will be deleted. x may also contain a wildcard pattern '*', which will delete all variables with names matching the wildcard pattern from memory.