在MATLAB中清除内存中的变量
在clearvars操作的帮助下,将变量从内存中清除。clearvars操作用于从内存或当前活动的工作区中清除指定的变量。
语法:
clearvars variables
clearvars -except keepVariables
参数: 该函数接受一个参数。
- variables。这些是要被清除的指定变量。
示例 1
% MATLAB code for variables "x" and "y"
% cleared from the memory and variable "z"
% will be as it is.
x = 5; % Initializing
y = 10;
z = 15;
% Calling the clearvars operation over
% the x and y variables
clearvars x y
% Getting the remaining variables
whos
输出:
示例 2
% MATLAB code for all variables will be
% cleared except "C" and "D".
A = 5; % Initializing of variables
B = 10;
C = 15;
D = 20;
E = 25;
% Calling the clearvars operation to
% clear above variables except C and D
clearvars -except C D
% Getting the remaining variables
whos
输出: