Code covered by the BSD License  

Highlights from
ccc

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

ccc

by

 

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
Description

This script contains only the following three lines of code:

close all;
clear all;
clc;

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.

Acknowledgements

This file inspired Cch and Clearempty.

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.

http://www.mathworks.com/matlabcentral/fileexchange/47609-nuke

23 Jul 2013 Stefan

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

clc;
myStops = dbstatus('-completenames');
save('myBreakpoints.mat','myStops');
close all;
clear -global;
clear all force;
clear classes;
load('myBreakpoints.mat');
dbstop(myStops);
clear myStops;
delete('myBreakpoints.mat');
disp('Cleaned up');

11 Jul 2013 Chad Greene

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.

11 Jul 2013 Jan Simon

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.

10 Jul 2013 Mikhail

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

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.

Updates
10 Jul 2013

Included a warning about using this function.

Contact us