This script contains only the following three lines of code:
It closes all figures, clears the workspace variables, clears all functions from memory, and clears the command window. The intent is to have a very quick method of getting a somewhat clean slate.
It may seem hardly worth writing a script for, and may seem too trivial to upload to FEX, but in the three months since I wrote this script I've thought at least a hundred times, "why didn't I write this earlier?" Hopefully it helps you just the same, or inspires you to write other simple functions that are tailored to your needs.
Note that if you have any functions in your memory, using this command may create headaches as you'll have to reload them.
I have uploaded a version that I use that does a decent amount of error checking prior to running the commands to ensure that there are no issues. It also incorporates fixes for a lot of the questions and concerns voiced here.
You bring up some great points, Jan. I hadn't seen the clr script which, you're right, does exactly the same thing as this one. For that reason, I'd remove mine from FEX, except that the value I see in the script here is that it's a quick-and-dirty command line shortcut. You've made it clear that "clear all" is dirty indeed. As for the quickness aspect, typing 'ccc' may be only marginally faster than typing 'clr', but only if you think of time in common units like seconds. My tests indicate that typing 'clr' requires approximately 43% more time and twice as many hands as typing 'ccc'. Clearly, 'ccc' is a vast improvement over 'clr'.
Joking aside, my message remains the same: download this if you want to, or simply write your own, tailored to your own needs. And likewise, if you've written scripts that you use frequently, upload them to the File Exchange. Others might benefit from them, be inspired by them, or offer insightful feedback such as Jan, Mikhail, and Stephen already have regarding this script.
You find exactly the same code in http://www.mathworks.com/matlabcentral/fileexchange/37058-clr-==-clear-all-close-all-clc .
And as there also, I want to stress that "clear all" even removes all debugger breakpoints. And everything, which impedes debugging is a really bad programming practize. It is very bewildering and even frustrating, that this brute clearing header is used such frequently by beginners on the top of all their scripts and even functions (where clearing the workspace is useless). It seems to be a fashion. And at the same time so many beginners could solve their problems alone instead of asking the forum, if they could use the debugger, avoid EVAL and understand that 0.3-0.2-0.1~=0 . So I'd wish, that the teachers or book authors, who suggest "clear all" would spend the time for useful suggestions.
Well, this isn't your fault and you've provided a warning already. You did not suggest to use this function inflationarily on the top of each function or script. And there could be good reasons to call this from the command line. To be exact, the possibility to call your function manually could discourage beginners to insert the three commands in their programs.
In consequence I would rate it with 1 star (due to the "clear all") or 5 stars (due to the fact, that it might reduce the number of "clear all"s inside code). Therefore I better omit the rating ;-) and stay a a suggestion for the users:
This is useful - if you use this with care and not in code, which will be debugged.