Orion42 ~IT made easy~

Solving common problem with out-of the box thinking

Matlab

[Matlab] How to quickly clean the workspace

How many times did it happen to you to close all the open window, remove the variable in the workspace and then clear the screen to start all over again from scratch? If this is the case, then just a few lines of code can save you a lot of time in the future.

Create a new .m file and copy those lines:

close all;    % Close all open figures 
clear;        % Clear all remove also break points
clear global; % Clear also global variables
clc;          % Clean the screen

with the comments in the code explaining what each command does.

Then save the file with a short name you easily remember – I choose “cc” (but t his name is also a built-in function that I do not use in one of the libraries). I suggest to put it in a folder where to save your other custom script. This folder can then be added it to the Matlab Path (Home tab > Set Path) so it will be automatically searched for form the command line.

Leave a Reply

Skip to content