do i have to write clc close all clear all in every code in matlab

Instead of writing clc, close all, and clear all at the beginning of every MATLAB code, you can create a script that you can call from other scripts to execute these commands. This way you only need to include it once.

Here's how you can do it:

main.m
% Create a new script named clearWorkspace.m
function clearWorkspace
    clc;         % Clear Command Window
    close all;   % Close all figures
    clear all;   % Clear workspace
end
185 chars
7 lines

You can then call this function at the beginning of your other MATLAB scripts or functions to clear the workspace:

main.m
clearWorkspace;
% Your MATLAB code goes here
45 chars
3 lines

By doing this, you won't have to write clc, close all, and clear all at the beginning of every MATLAB code.

related categories

gistlibby LogSnag