📜  在 MATLAB 中从内存中清除变量

📅  最后修改于: 2022-05-13 01:54:55.329000             🧑  作者: Mango

在 MATLAB 中从内存中清除变量

借助 clearvars 操作从内存中清除变量。 clearvars 操作用于从内存或当前活动工作区中清除指定的变量。

句法:

clearvars variables
clearvars -except keepVariables

参数:该函数接受一个参数。

  • 变量:这些是要清除的指定变量。

示例 1

Matlab
% 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


Matlab
% 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


输出:



示例 2

MATLAB

% 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

输出: