View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Be the first to rate this file! 5 Downloads (last 30 days) File Size: 1.06 KB File ID: #42559 Version: 1.1



Chad Greene (view profile)


09 Jul 2013 (Updated )

close all; clear all; clc;

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

This script contains only the following three lines of code:

close all;
clear all;

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.


This file inspired Clearempty and Cch Close, Clear, Home.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
20 Aug 2014 Jonathan Suever

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.

Comment only
23 Jul 2013 Stefan

Stefan (view profile)

Here is my version, which saves and restores breakpoints, so debugging will be no problem:

myStops = dbstatus('-completenames');
close all;
clear -global;
clear all force;
clear classes;
clear myStops;
disp('Cleaned up');

Comment only
11 Jul 2013 Chad Greene

Chad Greene (view profile)

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.

Comment only
11 Jul 2013 Jan Simon

Jan Simon (view profile)

You find exactly the same code in .

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.

Comment only
10 Jul 2013 Mikhail

Mikhail (view profile)

Mine also contains "bdclose all" to close all opened Simulink models.

Comment only
09 Jul 2013 Stephen Yutzy

It's the simple things that can be so useful sometimes. I've actually written something like this myself, with the addition of an "fclose all".

I would caution that clear all can be dangerous, especially if you think all it does is clear the workspace variables. You might want "clear variables" instead.

Comment only
10 Jul 2013 1.1

Included a warning about using this function.

Contact us