In MATLAB there is the function clear to delete all current variables. This is very useful if you start something totally new and don't want to get conflicts with earlier calculations. I'm searching something similar for Mathematica now, but I couldn't find anything except of Clear[VAR] which removes only the variable VAR.
相关问题
- Puzzled by Function body evaluation
- how to overload Times and Plus for matrix multipli
- AOSP Build TARGET_PRODUCT fails
- Modifying a Graphics3D object generated by Paramet
- Mathematica “AppendTo” function problem
相关文章
- histogram without vertical lines in Mathematica
- Entering data with Input[] in mathematica
- Using Fold to calculate the result of linear recur
- How should I write a function to be used in Apply
- NMinimize eats all memory b/c of unnecessary symbo
- Mathematica: set default value for argument to non
- how does mathematica determine which rule to use f
- Animate the movement of a point along the plot of
I recommend one of two methods:
1. Keyboard shortcut to Quit[] the kernel
There is a system file
KeyEventTranslations.tr
that you can edit to customize keyboard shortcuts. I, as others, have added Ctrl+Q toQuit[]
the kernel, allowing for a rapid clearing of all sessions variables. For more information on setting this up, see:2. Give the new Notebook a unique context
In Mathematica, the current
$Context
defines what Context unqualified symbol names belong to. By giving a new Notebook a unique Context, which is easily done through theEvaluation
menu, the symbols used in that Notebook will not collide with unqualified symbols in other Notebooks. See the following question for more detailed information:You can use
ClearAll
to clear the variables and their attributes in yourGlobal
context (default) like so:If you're working inside a different context (e.g., notebook specific context or cell group specific context), you can do
If you want to remove all symbols from the kernel so that Mathematica doesn't recognize them anymore, you can use
Remove[]
similar to the above two examples.Barring these, you can always quit the kernel with
Quit[]
which will remove all symbols. A fresh kernel will be initiated the next time you evaluate something.I just realized that you might not know that unlike MATLAB, Mathematica is designed to run as two separate processes: the Front End is the user interface, and lets you work with notebooks. The Kernel does the computations. You can quit the kernel without affecting the front end, or even start more than one kernel for different notebooks, or start a kernel on a remote computer and use it with a local front end.
I believe that the only reliable way to clean everything is to
Quit
the kernel and re-start it (which is automatic). There are just too many things that can get modified apart from user variables/functions (includingIn
/Out
, loaded packages, system caches, etc.). So if you need a truly fresh start, I recommendQuit
.For a "soft" reset, @yoda already mentioned
ClearAll["Global`*"]
. There's the<< Utilities`CleanSlate`
package, which automates a little bit more than this. You can read the package docs inside theAddOns\ExtraPackages\Utilities\CleanSlate.m
file.In short,
CleanSlate[]
will attempt to take you back to the kernel state when the package was loaded.ClearInOut[]
will clearIn
andOut
to save memory.I haven't used this package in years (except for the
ClearInOut[]
functionality), as the Mathematica kernel starts up quickly on modern computers, so I just useQuit
. So I can't tell you how well it works.