MATLAB: Does “clear” command clears the global variables

variablesworkspace

Does clear command clears all the variables in the workspace including global variables. In my code, there are lots of global variables. On running the code multiple times it seems that previous global variables are not getting cleared.
I'm using below command at the start of the Code
clear;

Best Answer

doc clear
gives a very clear description of the various arguments to clear and what gets cleared by each instruction.
Simply typing
clear
'removes all variables from the current workspace, releasing them from system memory.' to quote that documentation verbatim.
So as ever with global variables it is a murky mess depending whether they are in your workspace or not. If not then they won't be cleared.
Moral of the story is to simply not use globals and to read the documentation!!