Remove items from workspace, freeing up system memory
clear
removes all variables from the current
workspace, releasing them from system memory.
clear
removes
the variables, scripts, functions, or MEX-functions name1 ... nameN
name1
... nameN
from memory.
clear -regexp
removes
all variables that match any of the regular expressions listed. This
option only removes variables.expr1 ... exprN
Calling clear all
, clear
classes
, and clear functions
decreases
code performance, and is usually unnecessary.
To clear one or more specific variables from the current
workspace, use clear
.name1 ... nameN
To clear all variables from the current workspace,
use clear
or clearvars
.
To clear all global variables, use clear
global
or clearvars –global
.
To clear a particular class, use clear
.myClass
To clear a particular function or script, use clear
.functionName
To clear all MEX functions, use clear mex
.
The clear
function can remove
variables that you specify. To remove all except a few specified variables,
use clearvars
instead.
If you clear the handle of a figure or graphics object,
the object itself is not removed. Use delete
to
remove objects. On the other hand, deleting an object does not remove
the variable (if any) used for storing its handle.
The clear
function does not clear Simulink® models.
Use bdclose
instead.
The clear
function does not clear persistent variables in
local or nested functions.
On UNIX® systems, clear
does not affect the amount of
memory allocated to the MATLAB process.