|MATLAB Function Reference|
Remove items from workspace, freeing up system memory
As an alternative to the
clear function, use Clear Workspace in the MATLAB desktop Edit menu, or in the context menu in the Workspace browser.
removes all variables from the workspace. This frees up system memory.
removes just the M-file or MEX-file function or variable
name from the workspace. You can use wildcards (
*) to remove items selectively. For example,
clear my* removes any variables whose names begin with the string
my. It removes debugging breakpoints in M-files and reinitializes persistent variables, since the breakpoints for a function and persistent variables are cleared whenever the M-file is changed or cleared. If
name is global, it is removed from the current workspace, but left accessible to any functions declaring it global. If
name has been locked by
mlock, it remains in memory.
Use a partial path to distinguish between different overloaded versions of a function. For example,
clear inline/display clears only the
display method for
inline objects, leaving any other implementations in memory.
clear name1 name2 name3 ...
name3 from the workspace.
clear global name
removes the global variable
name is global,
clear name removes
name from the current workspace, but leaves it accessible to any functions declaring it global. Use
clear global name to completely remove a global variable.
clear clears the items indicated by
||Removes all variables, functions, and MEX-files from memory, leaving the workspace empty. Using
||The same as
||Clears all the currently compiled M-functions and MEX-functions from memory. Using
||Clears all global variables from the workspace.
||Removes the Java packages import list. It can only be issued from the Command Window prompt. It cannot be used in a function.
||Clears all variables from the workspace.
is the function form of the syntax. Use this form when the variable name or function name is stored in a string.
When you use
clear in a function, it has the following effect on items in your function and base workspaces:
nameis the name of a function, the function is cleared in both the function workspace and in your base workspace.
functions--All functions are cleared in both the function workspace and in your base workspace.
global--All global variables are cleared in both the function workspace and in your base workspace.
all--All functions, global variables, and classes are cleared in both the function workspace and in your base workspace.
clear does not affect the amount of memory allocated to the MATLAB process under UNIX.
Given a workspace containing the following variables
you can clear a single variable,
xint, by typing
To clear all global variables, type
To clear all compiled M- and MEX-functions from memory, type
clear functions. In the case shown below,
clear functions was unable to clear one M-file function from memory,
testfun, because the function is locked.
Once you unlock the function from memory, you can clear it.
munlocktestfun clear functions inmem ans = Empty cell array: 0-by-1