File Exchange

image thumbnail

Matlab Cleaner

version 1.0.1 (1.64 KB) by Christoph Müßig
A tool to instantly clean all variables, figures and the command window. With the parameters you can exclude variabels or clean help files.

1 Download

Updated 26 May 2019

View Version History

View License

I recently asked some Matlab users, what they would improve in this already fantastic programming language. One of the frequently mentioned ideas was a easy and less time consuming cleaner. My command windows history is full of:

(close all)
clear
clc

I thought about a simple function to save time and came up with my Cleaner. Now you can just type "c", press Enter and everything is clean again. To make it even more usefull, you can exclude variabels form beeing deleted and configure options, so for example it doesnt close all open figures.

c % Clean everything
c('a b') % Clean everything except the variables a and b
c('a b','c') % Clean everything except the variables a and b and dont clean the Command window

Additionally, by selecting 'p' as the second parameter, all the sometimes annoying help files (ending .asv) are cleaned from the Matlab paths. And you can combine multiple options as the second parameter, for example c('a b','fp') to clean all help files, but let the figures open.

I really hope, this function can help some people to save some time. If you have any ideas how to improve it, let me know :)

Cite As

Christoph Müßig (2021). Matlab Cleaner (https://www.mathworks.com/matlabcentral/fileexchange/71655-matlab-cleaner), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Leon Heiß

Christoph Müßig

@Rob Campbell
Of course ".asv" are autosave files, which are included in my definition of help files. But isn't that unnessesary quibbling?

My code ist also written in functions, but in many situations, it is very handy to check the variabels while debugging. Or when just experimenting in the command window, the cleaner can be very helpful. But yours tips with the figures are super, thank you very much. I thinking how to implement them.

Rob Campbell

I think this general problem can be fixed by changing work habits. If your code is neatly written in functions then there should be very little rubbish accumulating in the base workspace and consequently very little need to be regularly doing "clear all". I doubt I run that command more than every couple of weeks or so. As for "close all": in many cases you can replace a "figure" command in your functions with a "clf". That way you don't make new figures. Even better, you can make a new figure and tag it with "mfilename" then in future runs of the function test for the presence of that tagged figure and only make it again if it doesn't exist. Otherwise you bring it to focus and then clf. In this way you don't risk wiping a figure that contains something useful.

Rob Campbell

The ".asv" are autosave files, not help files.

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!