clear all
should not be used to clear only workspace
variables. In addition to clearing workspace variables, it also clears
functions and scripts. Using clear all
causes MATLAB to
recompile previously cached code, and can decrease performance.
When possible, replace instances of clear all
in your
code.
To clear one or more specific variables from the current workspace,
use clear var1
var2.
To clear all variables from the current workspace, consider using
clear variables
or
clearvars
.
To clear all global variables, consider using clear
global
or clearvars –global
.
To clear a function or script, consider clearing only the specific
function or script. For example, clear
myFun
.